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