AnalyticsProxy.coffee 621 B

1234567891011121314151617181920
  1. settings = require "settings-sharelatex"
  2. Errors = require '../Errors/Errors'
  3. httpProxy = require 'express-http-proxy'
  4. URL = require 'url'
  5. module.exports =
  6. call: (basePath) ->
  7. analyticsUrl = settings?.apis?.analytics?.url
  8. if analyticsUrl?
  9. httpProxy(analyticsUrl,
  10. proxyReqPathResolver: (req) ->
  11. requestPath = URL.parse(req.url).path
  12. "#{basePath}#{requestPath}"
  13. proxyReqOptDecorator: (proxyReqOpts, srcReq) ->
  14. proxyReqOpts.headers = {} # unset all headers
  15. proxyReqOpts
  16. )
  17. else
  18. (req, res, next) ->
  19. next(new Errors.ServiceNotConfiguredError('Analytics service not configured'))