Update routes to recognize index.html URLs
This commit is contained in:
+11
-9
@@ -12,8 +12,9 @@ path = require 'path'
|
|||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
ROOT = './dist/'
|
ROOT = './dist'
|
||||||
DATA_ROOT = '../crafting-guide-data'
|
DATA_ROOT = '../crafting-guide-data'
|
||||||
|
PRERENDER_ROOT = '../crafting-guide-prerender/static'
|
||||||
|
|
||||||
CONTENT_TYPE = {
|
CONTENT_TYPE = {
|
||||||
'.cg': 'text/plain'
|
'.cg': 'text/plain'
|
||||||
@@ -33,29 +34,30 @@ app = express()
|
|||||||
|
|
||||||
serveIndex = (request, response)->
|
serveIndex = (request, response)->
|
||||||
response.set 'Content-Type', 'text/html'
|
response.set 'Content-Type', 'text/html'
|
||||||
filePath = "#{request.path}index.html".replace /^\//, ''
|
filePath = "#{request.path}index.html".replace('index.htmlindex.html', 'index.html')
|
||||||
fs.stat "#{ROOT}#{filePath}", (err, stats)->
|
fs.stat "#{PRERENDER_ROOT}#{filePath}", (err, stats)->
|
||||||
if not err?
|
if not err?
|
||||||
response.sendFile filePath, root:ROOT
|
console.log ">>> #{request.path} ==> #{PRERENDER_ROOT}#{filePath}"
|
||||||
console.log ">>> #{filePath} (for #{request.path})"
|
response.sendFile filePath, root:PRERENDER_ROOT
|
||||||
else
|
else
|
||||||
|
console.log ">>> #{request.path} ==> #{ROOT}app.html"
|
||||||
response.sendFile '/app.html', root:ROOT
|
response.sendFile '/app.html', root:ROOT
|
||||||
console.log ">>> app.html (for #{request.path})"
|
|
||||||
|
|
||||||
serveData = (request, response)->
|
serveData = (request, response)->
|
||||||
console.log ">>> #{request.path}"
|
|
||||||
response.set 'Content-Type', CONTENT_TYPE[path.extname request.path]
|
response.set 'Content-Type', CONTENT_TYPE[path.extname request.path]
|
||||||
|
console.log ">>> #{request.path} ==> #{DATA_ROOT}#{request.path}"
|
||||||
response.sendFile request.path, root:DATA_ROOT
|
response.sendFile request.path, root:DATA_ROOT
|
||||||
|
|
||||||
app.get '/data/*', serveData
|
app.get '/data/*', serveData
|
||||||
|
|
||||||
app.get '/craft/*', serveIndex
|
app.get '/craft/*', serveIndex
|
||||||
app.get '/login', serveIndex
|
app.get '/login', serveIndex
|
||||||
|
app.get '*.html', serveIndex
|
||||||
app.get '*/$', serveIndex
|
app.get '*/$', serveIndex
|
||||||
|
|
||||||
app.get '*', (request, response)->
|
app.get '*', (request, response)->
|
||||||
console.log ">>> #{request.path}"
|
|
||||||
response.set 'Content-Type', CONTENT_TYPE[path.extname request.path]
|
response.set 'Content-Type', CONTENT_TYPE[path.extname request.path]
|
||||||
|
console.log ">>> #{request.path} ==> #{ROOT}#{request.path}"
|
||||||
response.sendFile request.path, root:ROOT
|
response.sendFile request.path, root:ROOT
|
||||||
|
|
||||||
server = app.listen 8000, '127.0.0.1', ->
|
server = app.listen 8000, '127.0.0.1', ->
|
||||||
|
|||||||
@@ -118,15 +118,15 @@ module.exports = class CraftingGuideRouter extends backbone.Router
|
|||||||
@_recordPageView()
|
@_recordPageView()
|
||||||
|
|
||||||
routes:
|
routes:
|
||||||
'(/)': 'route__home'
|
'(/(index.html))': 'route__home'
|
||||||
'browse(/)': 'route__browse'
|
'browse(/(index.html))': 'route__browse'
|
||||||
'browse/:modSlug(/)': 'route__browseMod'
|
'browse/:modSlug(/(index.html))': 'route__browseMod'
|
||||||
'browse/:modSlug/:itemSlug(/)': 'route__browseModItem'
|
'browse/:modSlug/:itemSlug(/(index.html))': 'route__browseModItem'
|
||||||
'browse/:modSlug/tutorials/:tutorialSlug(/)': 'route__browseTutorial'
|
'browse/:modSlug/tutorials/:tutorialSlug(/(index.html))': 'route__browseTutorial'
|
||||||
'configure(/)': 'route__configure'
|
'configure(/(index.html))': 'route__configure'
|
||||||
'craft(/)': 'route__craft'
|
'craft(/(index.html)': 'route__craft'
|
||||||
'craft/:text': 'route__craft'
|
'craft/:text': 'route__craft'
|
||||||
'login(/)': 'route__login'
|
'login(/(index.html))': 'route__login'
|
||||||
|
|
||||||
'item/:itemSlug': 'deprecated__item'
|
'item/:itemSlug': 'deprecated__item'
|
||||||
'crafting/(:text)': 'deprecated__crafting'
|
'crafting/(:text)': 'deprecated__crafting'
|
||||||
|
|||||||
Reference in New Issue
Block a user