mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
added redirects from config file in, used for old template paths
This commit is contained in:
parent
000be22f16
commit
978e3262b5
5 changed files with 74 additions and 6 deletions
|
@ -1,4 +1,6 @@
|
|||
settings = require("settings-sharelatex")
|
||||
logger = require("logger-sharelatex")
|
||||
|
||||
|
||||
module.exports =
|
||||
saveTemplateDataInSession: (req, res, next)->
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
settings = require("settings-sharelatex")
|
||||
logger = require("logger-sharelatex")
|
||||
|
||||
module.exports = (req, res, next)->
|
||||
|
||||
requestedUrl = req.url
|
||||
|
||||
redirectUrl = settings.redirects[requestedUrl]
|
||||
|
||||
#remove starting slash
|
||||
if !redirectUrl? and requestedUrl[requestedUrl.length-1] == "/"
|
||||
requestedUrl = requestedUrl.substring(0, requestedUrl.length - 1)
|
||||
redirectUrl = settings.redirects[requestedUrl]
|
||||
|
||||
if redirectUrl?
|
||||
logger.log redirectUrl:redirectUrl, reqUrl:req.url, "redirecting to new path"
|
||||
res.redirect 301, "#{redirectUrl}"
|
||||
else
|
||||
next()
|
||||
|
|
@ -16,6 +16,7 @@ sessionStore = new RedisStore(host:Settings.redis.web.host, port:Settings.redis.
|
|||
cookieParser = express.cookieParser(Settings.security.sessionSecret)
|
||||
oneDayInMilliseconds = 86400000
|
||||
ReferalConnect = require('../Features/Referal/ReferalConnect')
|
||||
RedirectManager = require("./RedirectManager")
|
||||
|
||||
metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongojs/node_modules/mongodb"), logger)
|
||||
metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongoose/node_modules/mongodb"), logger)
|
||||
|
@ -74,6 +75,7 @@ app.configure 'production', ->
|
|||
app.enable('view cache')
|
||||
|
||||
app.use metrics.http.monitor(logger)
|
||||
app.use RedirectManager
|
||||
|
||||
app.use (req, res, next)->
|
||||
metrics.inc "http-request"
|
||||
|
|
|
@ -266,9 +266,6 @@ module.exports =
|
|||
}]
|
||||
|
||||
|
||||
algolia:
|
||||
appId:"SK53GL4JLY"
|
||||
secret:"75dc5e65794cd47eb7f725e6bb5075be"
|
||||
|
||||
|
||||
redirects:
|
||||
"/templates/index": "/templates/"
|
||||
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
sinon = require('sinon')
|
||||
chai = require('chai')
|
||||
should = chai.should()
|
||||
expect = chai.expect
|
||||
path = require("path")
|
||||
modulePath = "../../../../app/js/infrastructure/RedirectManager.js"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe "redirectToNewTemplate", ->
|
||||
beforeEach ->
|
||||
@settings =
|
||||
redirects:
|
||||
"/path/here/" : "/path/elsewhere/"
|
||||
"/no/trailing/slash":"/no/trailing/slash/elsewhere"
|
||||
"/part/path": "/diff/part/path"
|
||||
mountPointUrl:"/here"
|
||||
@redirectManager = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex":@settings
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
@res =
|
||||
redirect: sinon.stub()
|
||||
@req = {}
|
||||
|
||||
describe "redirect", ->
|
||||
|
||||
it "should perminant redirect if url matches redirect", ()->
|
||||
@req.url = "/path/here/"
|
||||
nextStub = sinon.stub()
|
||||
@redirectManager @req, @res, nextStub
|
||||
@res.redirect.calledWith(301, "/path/elsewhere/").should.equal true
|
||||
nextStub.called.should.equal false
|
||||
|
||||
it "should not redirect on non matching url", (done)->
|
||||
@req.url = "non/matching/"
|
||||
@redirectManager @req, @res, =>
|
||||
@res.redirect.called.should.equal false
|
||||
done()
|
||||
|
||||
it "should ignore slash at end of url", ->
|
||||
@req.url = "/no/trailing/slash/"
|
||||
nextStub = sinon.stub()
|
||||
@redirectManager @req, @res, nextStub
|
||||
@res.redirect.calledWith(301, "/no/trailing/slash/elsewhere").should.equal true
|
||||
nextStub.called.should.equal false
|
||||
|
Loading…
Reference in a new issue