Set up a 301 Redirect for account/profile instead of a backbone redirect

This commit is contained in:
Ruben Vereecken 2014-07-13 22:34:32 +02:00
parent 8e82702348
commit 9db84befa6
2 changed files with 12 additions and 0 deletions

View file

@ -19,6 +19,9 @@ module.exports = class CocoRouter extends Backbone.Router
# user views
'user/:nameOrID(/:subview)': 'userView'
# account views
'account(/:subview)(/*rest)': 'accountView'
# Direct links
'test/*subpath': go('TestView')
'demo/*subpath': go('DemoView')
@ -58,6 +61,9 @@ module.exports = class CocoRouter extends Backbone.Router
view.render()
@openView if view then view else @notFoundView()
accountView: (nameOrID, subview) ->
cache: {}
openRoute: (route) ->
route = route.split('?')[0]

View file

@ -70,11 +70,17 @@ setupMiddlewareToSendOldBrowserWarningWhenPlayersViewLevelDirectly = (app) ->
return next() if req.query['try-old-browser-anyway'] or not isOldBrowser req
res.sendfile(path.join(__dirname, 'public', 'index_old_browser.html'))
setupRedirectMiddleware = (app) ->
app.all '/account/profile/*', (req, res, next) ->
nameOrID = req.path.split('/')[3]
res.redirect 301, "/user/#{nameOrID}/profile"
exports.setupMiddleware = (app) ->
setupMiddlewareToSendOldBrowserWarningWhenPlayersViewLevelDirectly app
setupExpressMiddleware app
setupPassportMiddleware app
setupOneSecondDelayMiddleware app
setupRedirectMiddleware app
###Routing function implementations###