overleaf/services/web/app/src/Features/Analytics/AnalyticsProxy.js
Eric Mc Sween fdb5386b85 Merge pull request #5547 from overleaf/em-ta-analytics-proxy-fix
Fix how AnalyticsProxy generates the URL

GitOrigin-RevId: 272e7ea92d1aa41f7390d39c590336a23dba3708
2021-10-22 08:04:20 +00:00

28 lines
775 B
JavaScript

const settings = require('@overleaf/settings')
const Errors = require('../Errors/Errors')
const httpProxy = require('express-http-proxy')
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) {
// req.url is the part of the path that comes after the mount point in
// app.use()
return `${basePath}${req.url}`
},
proxyReqOptDecorator(proxyReqOpts, srcReq) {
proxyReqOpts.headers = {} // unset all headers
return proxyReqOpts
},
})
},
}