overleaf/services/web/app/coffee/Features/Analytics/AnalyticsProxy.coffee
2018-01-10 15:03:14 +02:00

17 lines
500 B
CoffeeScript

settings = require "settings-sharelatex"
Errors = require '../Errors/Errors'
httpProxy = require 'express-http-proxy'
URL = require 'url'
module.exports =
call: (basePath) ->
analyticsUrl = settings?.apis?.analytics?.url
if analyticsUrl?
httpProxy(analyticsUrl,
proxyReqPathResolver: (req) ->
requestPath = URL.parse(req.url).path
"#{basePath}#{requestPath}"
)
else
(req, res, next) ->
next(new Errors.ServiceNotConfiguredError('Analytics service not configured'))