2021-07-07 05:38:56 -04:00
|
|
|
const settings = require('@overleaf/settings')
|
2019-05-29 05:21:06 -04:00
|
|
|
const Errors = require('../Errors/Errors')
|
|
|
|
const httpProxy = require('express-http-proxy')
|
|
|
|
|
|
|
|
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) {
|
2021-10-21 14:37:09 -04:00
|
|
|
// req.url is the part of the path that comes after the mount point in
|
|
|
|
// app.use()
|
|
|
|
return `${basePath}${req.url}`
|
2019-06-21 05:57:43 -04:00
|
|
|
},
|
|
|
|
proxyReqOptDecorator(proxyReqOpts, srcReq) {
|
|
|
|
proxyReqOpts.headers = {} // unset all headers
|
|
|
|
return proxyReqOpts
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-06-21 05:57:43 -04:00
|
|
|
})
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|