From 8cde02a10b66c22d1954fa03064d3aba96c3ab53 Mon Sep 17 00:00:00 2001 From: Andrew Miner Date: Sun, 28 Dec 2014 12:58:53 -0800 Subject: [PATCH] Update test server to use Express --- scripts/server | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/scripts/server b/scripts/server index 793625dbd..879dcbc2d 100755 --- a/scripts/server +++ b/scripts/server @@ -1,4 +1,43 @@ -#!/bin/bash +#!/usr/bin/env coffee +# +# Crafting Guide - server +# +# Copyright (c) 2014 by Redwood Labs +# All rights reserved. +# -http-server dist -p 8000 -c-1 --cors +express = require 'express' +path = require 'path' +######################################################################################################################## + +ROOT = './dist/' + +######################################################################################################################## + +app = express() + +app.get '/item/*', (request, response)-> + console.log ">>> index.html (for #{request.path})" + response.set 'Content-Type', 'text/html' + response.sendFile 'index.html', root:ROOT + +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}"