Restructure static files into a single directory

This commit is contained in:
Andrew Miner
2015-03-08 15:05:24 -07:00
parent 997b37ab7d
commit 0a6c185965
5053 changed files with 383 additions and 175 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash
OUTPUT_DIR='./prerender'
OUTPUT_DIR='./static'
SCRIPT='/tmp/phantomjs_render.coffee'
if [[ "$1" != "" ]]; then
-41
View File
@@ -1,41 +0,0 @@
#!/usr/bin/env coffee
#
# Crafting Guide - serve-prerendered
#
# Copyright (c) 2014-2015 by Redwood Labs
# All rights reserved.
#
express = require 'express'
path = require 'path'
########################################################################################################################
ROOT = './dist'
########################################################################################################################
app = express()
app.get '*', (request, response)->
effectivePath = request.path.replace /\/$/, '/index.html'
extension = path.extname(effectivePath)
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 ">>> #{effectivePath}"
response.set 'Content-Type', contentType
setTimeout (-> response.sendFile effectivePath, root:ROOT), 100 # post files after a short delay
server = app.listen 8001, ->
console.log "listening at: #{server.address().address}:#{server.address().port}"
+10 -11
View File
@@ -7,6 +7,7 @@
#
express = require 'express'
fs = require 'fs'
path = require 'path'
########################################################################################################################
@@ -17,18 +18,16 @@ ROOT = './dist/'
app = express()
serveIndex = (request, response)->
console.log ">>> index.html (for #{request.path})"
app.get '*/$', (request, response)->
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
filePath = "#{request.path}index.html"
fs.stat "#{ROOT}#{filePath}", (err, stats)->
if stats.isFile()
response.sendFile filePath, root:ROOT
console.log ">>> #{filePath} (for #{request.path})"
else
response.sendFile '/index.html', root:ROOT
console.log ">>> index.html (for #{request.path})"
app.get '*', (request, response)->
extension = path.extname(request.path)