AnalyticsProxy.js 757 B

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