Restructure static files into a single directory
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
OUTPUT_DIR='./prerender'
|
||||
OUTPUT_DIR='./static'
|
||||
SCRIPT='/tmp/phantomjs_render.coffee'
|
||||
|
||||
if [[ "$1" != "" ]]; then
|
||||
|
||||
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user