2019-05-29 05:21:06 -04:00
|
|
|
const settings = require('settings-sharelatex')
|
|
|
|
const Errors = require('../Errors/Errors')
|
|
|
|
const httpProxy = require('express-http-proxy')
|
|
|
|
const URL = require('url')
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
call(basePath) {
|
2019-06-21 05:57:43 -04:00
|
|
|
if (!settings.apis.analytics) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return (req, res, next) =>
|
|
|
|
next(
|
|
|
|
new Errors.ServiceNotConfiguredError(
|
|
|
|
'Analytics service not configured'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-06-21 05:57:43 -04:00
|
|
|
return httpProxy(settings.apis.analytics.url, {
|
|
|
|
proxyReqPathResolver(req) {
|
|
|
|
const requestPath = URL.parse(req.url).path
|
|
|
|
return `${basePath}${requestPath}`
|
|
|
|
},
|
|
|
|
proxyReqOptDecorator(proxyReqOpts, srcReq) {
|
|
|
|
proxyReqOpts.headers = {} // unset all headers
|
|
|
|
return proxyReqOpts
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|