Created
September 27, 2016 14:46
-
-
Save nicroto/3ebdde47490958f15d3ab59a8bf7e1cd to your computer and use it in GitHub Desktop.
NodeJS server for a single-page app with client navigation and no backend.
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
'use strict'; | |
var http = require( "http" ), | |
pathUtils = require( "path" ), | |
express = require( "express" ), | |
app = express(), | |
PORT = process.env.PORT || 5000, | |
appDir = pathUtils.resolve( __dirname, "client" ); | |
app.use( express.static( appDir ) ); | |
app.get( "*", function( req, res ) { | |
res.sendfile( pathUtils.resolve( appDir, "index.html" ) ); | |
} ); | |
http.createServer( app ).listen( PORT, function() { | |
console.log( "Express server listening on port " + PORT ); | |
console.log( "http://localhost:" + PORT ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment