2014-02-12 10:23:40 +00:00
|
|
|
request = require 'request'
|
|
|
|
Settings = require 'settings-sharelatex'
|
|
|
|
logger = require 'logger-sharelatex'
|
2016-09-05 14:58:31 +00:00
|
|
|
AuthenticationController = require('../Authentication/AuthenticationController')
|
2014-02-12 10:23:40 +00:00
|
|
|
|
2015-10-22 19:15:50 +00:00
|
|
|
TEN_SECONDS = 1000 * 10
|
|
|
|
|
2014-02-12 10:23:40 +00:00
|
|
|
module.exports = SpellingController =
|
|
|
|
proxyRequestToSpellingApi: (req, res, next) ->
|
2016-09-05 14:58:31 +00:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
2014-02-12 10:23:40 +00:00
|
|
|
url = req.url.slice("/spelling".length)
|
2016-09-05 14:58:31 +00:00
|
|
|
url = "/user/#{user_id}#{url}"
|
2014-02-12 10:23:40 +00:00
|
|
|
req.headers["Host"] = Settings.apis.spelling.host
|
2015-10-22 19:15:50 +00:00
|
|
|
request(url: Settings.apis.spelling.url + url, method: req.method, headers: req.headers, json: req.body, timeout:TEN_SECONDS)
|
|
|
|
.on "error", (error) ->
|
2014-02-12 10:23:40 +00:00
|
|
|
logger.error err: error, "Spelling API error"
|
2016-05-24 14:11:14 +00:00
|
|
|
res.status(500).end()
|
2015-10-22 19:15:50 +00:00
|
|
|
.pipe(res)
|