overleaf/services/web/app/coffee/Features/History/HistoryController.coffee

28 lines
835 B
CoffeeScript
Raw Normal View History

2014-03-05 11:31:52 -05:00
logger = require "logger-sharelatex"
request = require "request"
settings = require "settings-sharelatex"
AuthenticationController = require "../Authentication/AuthenticationController"
2014-03-05 11:31:52 -05:00
module.exports = HistoryController =
proxyToHistoryApi: (req, res, next = (error) ->) ->
2016-09-05 10:58:31 -04:00
user_id = AuthenticationController.getLoggedInUserId req
2017-10-11 06:18:34 -04:00
url = HistoryController.buildHistoryServiceUrl() + req.url
2016-09-05 10:58:31 -04:00
logger.log url: url, "proxying to track-changes api"
getReq = request(
url: url
method: req.method
headers:
"X-User-Id": user_id
)
getReq.pipe(res)
getReq.on "error", (error) ->
logger.error err: error, "track-changes API error"
next(error)
2017-10-11 06:18:34 -04:00
buildHistoryServiceUrl: () ->
if settings.apis.project_history.enabled
return settings.apis.project_history.url
else
return settings.apis.trackchanges.url