Intelligently redirect to v1 if no v2 project found for token

This commit is contained in:
Alasdair Smith 2018-09-10 17:21:58 +01:00
parent 24c479e984
commit e0ce988d32
2 changed files with 12 additions and 1 deletions

View file

@ -3,9 +3,19 @@ AuthenticationController = require '../Authentication/AuthenticationController'
TokenAccessHandler = require './TokenAccessHandler'
Errors = require '../Errors/Errors'
logger = require 'logger-sharelatex'
settings = require 'settings-sharelatex'
module.exports = TokenAccessController =
redirectNotFoundErrorToV1: (err, req, res, next) ->
if err instanceof Errors.NotFoundError and settings.overleaf
logger.log {
token: req.params['read_and_write_token']
}, "[TokenAccess] No project found for token, redirecting to v1"
res.redirect(settings.overleaf.host + req.url)
else
next(err)
_loadEditor: (projectId, req, res, next) ->
req.params.Project_id = projectId.toString()
return ProjectController.loadEditor(req, res, next)

View file

@ -426,6 +426,7 @@ module.exports = class Router
maxRequests: 10,
timeInterval: 60
}),
TokenAccessController.readAndWriteToken
TokenAccessController.readAndWriteToken,
TokenAccessController.redirectNotFoundErrorToV1
webRouter.get '*', ErrorController.notFound