Files
overleaf-cep/services/web/app/src/Features/Analytics/AnalyticsProxy.js
T
Simon Detheridge d1e587a51e Merge pull request #1864 from overleaf/ta-analytics-backoff-strategy
Update Analytics Backoff Strategy

GitOrigin-RevId: 9a3dc11ee19ff03432730a36617208ac7f58c5be
2019-06-21 10:10:52 +00:00

29 lines
757 B
JavaScript

const settings = require('settings-sharelatex')
const Errors = require('../Errors/Errors')
const httpProxy = require('express-http-proxy')
const URL = require('url')
module.exports = {
call(basePath) {
if (!settings.apis.analytics) {
return (req, res, next) =>
next(
new Errors.ServiceNotConfiguredError(
'Analytics service not configured'
)
)
}
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
}
})
}
}