mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Move trailing slash removal to client Router, make client route "/play/" work for facebook
This commit is contained in:
parent
70c18ca2cc
commit
94d29d2e8a
2 changed files with 5 additions and 7 deletions
|
@ -112,7 +112,7 @@ module.exports = class CocoRouter extends Backbone.Router
|
|||
|
||||
'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': go('ladder/LadderView')
|
||||
'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('EmployersView') # Show the not-recruiting-now screen
|
||||
|
||||
'*name/': 'removeTrailingSlash'
|
||||
'*name': go('NotFoundView')
|
||||
|
||||
routeToServer: (e) ->
|
||||
window.location.href = window.location.href
|
||||
|
||||
removeTrailingSlash: (e) ->
|
||||
@navigate e, {trigger: true}
|
||||
|
||||
routeDirectly: (path, args) ->
|
||||
path = "views/#{path}" if not _.string.startsWith(path, 'views/')
|
||||
ViewClass = @tryToLoadModule path
|
||||
|
|
|
@ -128,11 +128,6 @@ setupRedirectMiddleware = (app) ->
|
|||
nameOrID = req.path.split('/')[3]
|
||||
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) ->
|
||||
setupCountryRedirectMiddleware app, "china", "CN", "zh", "tokyo"
|
||||
|
@ -141,7 +136,6 @@ exports.setupMiddleware = (app) ->
|
|||
setupExpressMiddleware app
|
||||
setupPassportMiddleware app
|
||||
setupOneSecondDelayMiddleware app
|
||||
setupTrailingSlashRemovingMiddleware app
|
||||
setupRedirectMiddleware app
|
||||
setupErrorMiddleware app
|
||||
setupJavascript404s app
|
||||
|
|
Loading…
Reference in a new issue