Update routes to recognize index.html URLs

This commit is contained in:
Andrew Miner
2015-05-11 10:45:56 -07:00
parent 9e318df625
commit f40f6c8d71
2 changed files with 20 additions and 18 deletions
+11 -9
View File
@@ -12,8 +12,9 @@ path = require 'path'
########################################################################################################################
ROOT = './dist/'
DATA_ROOT = '../crafting-guide-data'
ROOT = './dist'
DATA_ROOT = '../crafting-guide-data'
PRERENDER_ROOT = '../crafting-guide-prerender/static'
CONTENT_TYPE = {
'.cg': 'text/plain'
@@ -33,29 +34,30 @@ app = express()
serveIndex = (request, response)->
response.set 'Content-Type', 'text/html'
filePath = "#{request.path}index.html".replace /^\//, ''
fs.stat "#{ROOT}#{filePath}", (err, stats)->
filePath = "#{request.path}index.html".replace('index.htmlindex.html', 'index.html')
fs.stat "#{PRERENDER_ROOT}#{filePath}", (err, stats)->
if not err?
response.sendFile filePath, root:ROOT
console.log ">>> #{filePath} (for #{request.path})"
console.log ">>> #{request.path} ==> #{PRERENDER_ROOT}#{filePath}"
response.sendFile filePath, root:PRERENDER_ROOT
else
console.log ">>> #{request.path} ==> #{ROOT}app.html"
response.sendFile '/app.html', root:ROOT
console.log ">>> app.html (for #{request.path})"
serveData = (request, response)->
console.log ">>> #{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
app.get '/data/*', serveData
app.get '/craft/*', serveIndex
app.get '/login', serveIndex
app.get '*.html', serveIndex
app.get '*/$', serveIndex
app.get '*', (request, response)->
console.log ">>> #{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
server = app.listen 8000, '127.0.0.1', ->