Last active
August 29, 2015 14:01
-
-
Save garris/37104cfb69406d575c28 to your computer and use it in GitHub Desktop.
simple node+express app to host static SPA file over http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express') | |
,app = express() | |
,_ = require('underscore') | |
,util = require('util') | |
,os = require('os'); | |
var rootDir = __dirname + '/app' | |
,port = 3000; | |
app.use(express.static(rootDir)); | |
app.listen(port); | |
//=================== | |
console.log('Serving files from: '+rootDir) | |
console.log('Listening on: ' + getAddresses() + ':' + port + ''); | |
console.log('Press Ctrl + C to stop.'); | |
function getAddresses(){ | |
var interfaces = os.networkInterfaces(), | |
addresses = []; | |
_.each(interfaces,function(net){ | |
_.each(net,function(address){ | |
if (address.family == 'IPv4' && !address.internal) addresses.push(address.address); | |
}) | |
}) | |
return addresses; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SPA server
This will serve index.html at the current directory path + /app.
To run, enter:
node server.js