diff --git a/services/web/app/coffee/infrastructure/Server.coffee b/services/web/app/coffee/infrastructure/Server.coffee index 122762f349..23a6dc337a 100644 --- a/services/web/app/coffee/infrastructure/Server.coffee +++ b/services/web/app/coffee/infrastructure/Server.coffee @@ -42,8 +42,6 @@ AuthenticationController = require "../Features/Authentication/AuthenticationCon metrics.event_loop?.monitor(logger) -Settings.editorIsOpen ||= true - if Settings.cacheStaticAssets staticCacheAge = (oneDayInMilliseconds * 365) else @@ -135,6 +133,13 @@ app.use (req, res, next)-> crawlerLogger.log(req) next() +webRouter.use (req, res, next) -> + if Settings.siteIsOpen + next() + else + res.status(503) + res.render("general/closed", {title:"maintenance"}) + webRouter.use (req, res, next) -> if Settings.editorIsOpen next() diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index 8d101b4302..9a8cdc0bee 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -425,6 +425,8 @@ module.exports = class Router webRouter.post '/admin/messages', AuthorizationMiddlewear.ensureUserIsSiteAdmin, AdminController.createMessage webRouter.post '/admin/messages/clear', AuthorizationMiddlewear.ensureUserIsSiteAdmin, AdminController.clearMessages + privateApiRouter.post '/disconnectAllUsers', AdminController.dissconectAllUsers + privateApiRouter.get '/perfTest', (req,res)-> res.send("hello") diff --git a/services/web/app/views/general/closed.pug b/services/web/app/views/general/closed.pug index 57c4b6023b..b179df1b35 100644 --- a/services/web/app/views/general/closed.pug +++ b/services/web/app/views/general/closed.pug @@ -8,7 +8,7 @@ block content .page-header h1 Maintenance p - | Sorry, ShareLaTeX is briefly down for maintenance. + | Sorry, #{settings.appName} is briefly down for maintenance. | We should be back within minutes, but if not, or you have | an urgent request, please contact us at |  #{settings.adminEmail} diff --git a/services/web/config/settings.defaults.coffee b/services/web/config/settings.defaults.coffee index 38273160bb..34bccf4bf8 100644 --- a/services/web/config/settings.defaults.coffee +++ b/services/web/config/settings.defaults.coffee @@ -350,6 +350,12 @@ module.exports = settings = # public projects, /learn, /templates, about pages, etc. allowPublicAccess: if process.env["SHARELATEX_ALLOW_PUBLIC_ACCESS"] == 'true' then true else false + # editor should be open by default + editorIsOpen: if process.env["EDITOR_OPEN"] == 'false' then false else true + + # site should be open by default + siteIsOpen: if process.env["SITE_OPEN"] == 'false' then false else true + # Use a single compile directory for all users in a project # (otherwise each user has their own directory) # disablePerUserCompiles: true diff --git a/services/web/test/acceptance/coffee/CloseSiteTests.coffee b/services/web/test/acceptance/coffee/CloseSiteTests.coffee new file mode 100644 index 0000000000..5409c712b7 --- /dev/null +++ b/services/web/test/acceptance/coffee/CloseSiteTests.coffee @@ -0,0 +1,22 @@ +Settings = require "settings-sharelatex" +chai = require "chai" +request = require "./helpers/request" + +describe "siteIsOpen", -> + describe "when siteIsOpen is default (true)", -> + it "should get page", (done) -> + request.get "/login", (error, response, body) -> + response.statusCode.should.equal 200 + done() + + describe "when siteIsOpen is false", -> + beforeEach -> + Settings.siteIsOpen = false + + afterEach -> + Settings.siteIsOpen = true + + it "should return maintenance page", (done) -> + request.get "/login", (error, response) -> + response.statusCode.should.equal 503 + done()