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')
|
|
|
|
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
|
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
|
|
|
}
|