Merge pull request #513 from sharelatex/bg-split-web-and-web-api

split web and web api
This commit is contained in:
Brian Gough 2017-07-04 08:51:00 +01:00 committed by GitHub
commit dbbc4966d8
2 changed files with 23 additions and 10 deletions

View file

@ -161,16 +161,24 @@ app.get "/heapdump", (req, res)->
logger.info ("creating HTTP server").yellow logger.info ("creating HTTP server").yellow
server = require('http').createServer(app) server = require('http').createServer(app)
# process api routes first, if nothing matched fall though and use # provide settings for separate web and api processes
# web middlewear + routes # if enableApiRouter and enableWebRouter are not defined they default
# to true.
notDefined = (x) -> !x?
enableApiRouter = Settings.web?.enableApiRouter
if enableApiRouter or notDefined(enableApiRouter)
logger.info("providing api router");
app.use(apiRouter) app.use(apiRouter)
app.use(ErrorController.handleApiError) app.use(ErrorController.handleApiError)
enableWebRouter = Settings.web?.enableWebRouter
if enableWebRouter or notDefined(enableWebRouter)
logger.info("providing web router");
app.use(webRouter) app.use(webRouter)
app.use(ErrorController.handleError) app.use(ErrorController.handleError)
router = new Router(webRouter, apiRouter) router = new Router(webRouter, apiRouter)
module.exports = module.exports =
app: app app: app
server: server server: server

View file

@ -271,16 +271,21 @@ module.exports = class Router
apiRouter.get '/perfTest', (req,res)-> apiRouter.get '/perfTest', (req,res)->
res.send("hello") res.send("hello")
apiRouter.get '/status', (req,res)-> webRouter.get '/status', (req,res)->
res.send("websharelatex is up") res.send("websharelatex is up")
apiRouter.get '/status', (req,res)->
res.send("websharelatex api is up")
webRouter.get '/dev/csrf', (req, res) -> webRouter.get '/dev/csrf', (req, res) ->
res.send res.locals.csrfToken res.send res.locals.csrfToken
webRouter.get '/health_check', HealthCheckController.check
apiRouter.get '/health_check', HealthCheckController.check apiRouter.get '/health_check', HealthCheckController.check
webRouter.get '/health_check/redis', HealthCheckController.checkRedis
apiRouter.get '/health_check/redis', HealthCheckController.checkRedis apiRouter.get '/health_check/redis', HealthCheckController.checkRedis
apiRouter.get "/status/compiler/:Project_id", AuthorizationMiddlewear.ensureUserCanReadProject, (req, res) -> webRouter.get "/status/compiler/:Project_id", AuthorizationMiddlewear.ensureUserCanReadProject, (req, res) ->
project_id = req.params.Project_id project_id = req.params.Project_id
sendRes = _.once (statusCode, message)-> sendRes = _.once (statusCode, message)->
res.status statusCode res.status statusCode
@ -303,7 +308,7 @@ module.exports = class Router
else else
sendRes 500, "Compiler returned failure #{status}" sendRes 500, "Compiler returned failure #{status}"
apiRouter.get "/ip", (req, res, next) -> webRouter.get "/ip", (req, res, next) ->
res.send({ res.send({
ip: req.ip ip: req.ip
ips: req.ips ips: req.ips