2014-03-05 16:31:52 +00:00
|
|
|
logger = require "logger-sharelatex"
|
|
|
|
request = require "request"
|
|
|
|
settings = require "settings-sharelatex"
|
2014-03-11 18:01:14 +00:00
|
|
|
AuthenticationController = require "../Authentication/AuthenticationController"
|
2014-03-05 16:31:52 +00:00
|
|
|
|
|
|
|
module.exports = TrackChangesController =
|
|
|
|
proxyToTrackChangesApi: (req, res, next = (error) ->) ->
|
2014-03-11 18:01:14 +00:00
|
|
|
AuthenticationController.getLoggedInUserId req, (error, user_id) ->
|
|
|
|
return next(error) if error?
|
|
|
|
url = settings.apis.trackchanges.url + req.url
|
|
|
|
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)
|