Move trailing slash removal to client Router, make client route "/play/" work for facebook

This commit is contained in:
Scott Erickson 2015-10-21 16:34:25 -07:00
parent 70c18ca2cc
commit 94d29d2e8a
2 changed files with 5 additions and 7 deletions

View file

@ -112,7 +112,7 @@ module.exports = class CocoRouter extends Backbone.Router
'multiplayer': go('MultiplayerView') 'multiplayer': go('MultiplayerView')
'play': go('play/CampaignView') 'play(/)': go('play/CampaignView') # extra slash is to get Facebook app to work
'play/ladder/:levelID/:leagueType/:leagueID': go('ladder/LadderView') 'play/ladder/:levelID/:leagueType/:leagueID': go('ladder/LadderView')
'play/ladder/:levelID': go('ladder/LadderView') 'play/ladder/:levelID': go('ladder/LadderView')
'play/ladder': go('ladder/MainLadderView') 'play/ladder': go('ladder/MainLadderView')
@ -131,11 +131,15 @@ module.exports = class CocoRouter extends Backbone.Router
#'user/:slugOrID/profile': go('user/JobProfileView') #'user/:slugOrID/profile': go('user/JobProfileView')
'user/:slugOrID/profile': go('EmployersView') # Show the not-recruiting-now screen 'user/:slugOrID/profile': go('EmployersView') # Show the not-recruiting-now screen
'*name/': 'removeTrailingSlash'
'*name': go('NotFoundView') '*name': go('NotFoundView')
routeToServer: (e) -> routeToServer: (e) ->
window.location.href = window.location.href window.location.href = window.location.href
removeTrailingSlash: (e) ->
@navigate e, {trigger: true}
routeDirectly: (path, args) -> routeDirectly: (path, args) ->
path = "views/#{path}" if not _.string.startsWith(path, 'views/') path = "views/#{path}" if not _.string.startsWith(path, 'views/')
ViewClass = @tryToLoadModule path ViewClass = @tryToLoadModule path

View file

@ -128,11 +128,6 @@ setupRedirectMiddleware = (app) ->
nameOrID = req.path.split('/')[3] nameOrID = req.path.split('/')[3]
res.redirect 301, "/user/#{nameOrID}/profile" res.redirect 301, "/user/#{nameOrID}/profile"
setupTrailingSlashRemovingMiddleware = (app) ->
app.use (req, res, next) ->
# Remove trailing slashes except for in /file/.../ URLs, because those are treated as directory listings.
return res.redirect 301, req.url[...-1] if req.url.length > 1 and req.url.slice(-1) is '/' and not /\/file\//.test req.url
next()
exports.setupMiddleware = (app) -> exports.setupMiddleware = (app) ->
setupCountryRedirectMiddleware app, "china", "CN", "zh", "tokyo" setupCountryRedirectMiddleware app, "china", "CN", "zh", "tokyo"
@ -141,7 +136,6 @@ exports.setupMiddleware = (app) ->
setupExpressMiddleware app setupExpressMiddleware app
setupPassportMiddleware app setupPassportMiddleware app
setupOneSecondDelayMiddleware app setupOneSecondDelayMiddleware app
setupTrailingSlashRemovingMiddleware app
setupRedirectMiddleware app setupRedirectMiddleware app
setupErrorMiddleware app setupErrorMiddleware app
setupJavascript404s app setupJavascript404s app