2017-12-21 08:51:52 -05:00
|
|
|
settings = require "settings-sharelatex"
|
|
|
|
Errors = require '../Errors/Errors'
|
|
|
|
httpProxy = require 'express-http-proxy'
|
|
|
|
URL = require 'url'
|
|
|
|
|
|
|
|
module.exports =
|
|
|
|
call: (basePath) ->
|
|
|
|
analyticsUrl = settings?.apis?.analytics?.url
|
|
|
|
if analyticsUrl?
|
|
|
|
httpProxy(analyticsUrl,
|
|
|
|
proxyReqPathResolver: (req) ->
|
|
|
|
requestPath = URL.parse(req.url).path
|
|
|
|
"#{basePath}#{requestPath}"
|
2018-01-11 12:04:41 -05:00
|
|
|
proxyReqOptDecorator: (proxyReqOpts, srcReq) ->
|
|
|
|
proxyReqOpts.headers = {} # unset all headers
|
|
|
|
proxyReqOpts
|
2017-12-21 08:51:52 -05:00
|
|
|
)
|
|
|
|
else
|
|
|
|
(req, res, next) ->
|
|
|
|
next(new Errors.ServiceNotConfiguredError('Analytics service not configured'))
|