AnalyticsProxy.js 775 B

12345678910111213141516171819202122232425262728
  1. const settings = require('@overleaf/settings')
  2. const Errors = require('../Errors/Errors')
  3. const httpProxy = require('express-http-proxy')
  4. module.exports = {
  5. call(basePath) {
  6. if (!settings.apis.analytics) {
  7. return (req, res, next) =>
  8. next(
  9. new Errors.ServiceNotConfiguredError(
  10. 'Analytics service not configured'
  11. )
  12. )
  13. }
  14. return httpProxy(settings.apis.analytics.url, {
  15. proxyReqPathResolver(req) {
  16. // req.url is the part of the path that comes after the mount point in
  17. // app.use()
  18. return `${basePath}${req.url}`
  19. },
  20. proxyReqOptDecorator(proxyReqOpts, srcReq) {
  21. proxyReqOpts.headers = {} // unset all headers
  22. return proxyReqOpts
  23. },
  24. })
  25. },
  26. }