Files
website/scripts/server
T
Andrew Miner 6c7274c38c Improve SEO by pre-rendering all HTML pages
* Change all internal links to use URLs ending in `/`
* Add the prerender script which uses PhantomJS to pre-render the
  HTML for all possible pages in the system
* Change the build process to incorporate the pre-rendered files
* Update the sitemap script to generate the new URLs
2015-03-06 22:31:39 -08:00

52 lines
1.5 KiB
CoffeeScript
Executable File

#!/usr/bin/env coffee
#
# Crafting Guide - serve-build
#
# Copyright (c) 2014-2015 by Redwood Labs
# All rights reserved.
#
express = require 'express'
path = require 'path'
########################################################################################################################
ROOT = './dist/'
########################################################################################################################
app = express()
serveIndex = (request, response)->
console.log ">>> index.html (for #{request.path})"
response.set 'Content-Type', 'text/html'
response.sendFile 'index.html', root:ROOT
app.get '/', serveIndex
app.get '/browse(/*)?', serveIndex
app.get '/configure(/*)?', serveIndex
app.get '/craft(/*)?', serveIndex
app.get '/crafting(/*)?', serveIndex
app.get '/item(/*)?', serveIndex
app.get '/mod(/*)?', serveIndex
app.get '*', (request, response)->
extension = path.extname(request.path)
contentType = {
'.css': 'text/css'
'.html': 'text/html'
'.js': 'text/javascript'
'.json': 'application/json'
'.map': 'application/json'
'.png': 'image/png'
'.ttf': 'application/octet-stream'
'.scss': 'text/css'
}[extension]
console.log ">>> #{request.path}"
response.set 'Content-Type', contentType
response.sendFile request.path, root:ROOT
server = app.listen 8000, ->
console.log "listening at: #{server.address().address}:#{server.address().port}"