Last active
June 14, 2021 06:50
-
-
Save marlun78/10755657 to your computer and use it in GitHub Desktop.
Super simple express sever for serving static content
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
/** | |
* Simple express sever | |
* Copyright (c) 2014, marlun78 | |
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83 | |
* | |
* Assumes this folder structure | |
* /public | |
* /server | |
* | |
* Express: http://expressjs.com | |
*/ | |
var app, server, | |
express = require('express'), | |
path = require('path'), | |
host = process.env.HOST || '127.0.0.1', | |
port = process.env.PORT || 3000, | |
root = path.resolve(__dirname, '..'); | |
app = express(); | |
app.use(function(req, res, next) { console.log(req.url); next(); }); | |
app.use(express.static(root + '/public')); | |
server = app.listen(port, host, serverStarted); | |
function serverStarted () { | |
console.log('Server started', host, port); | |
console.log('Root directory', root); | |
console.log('Press Ctrl+C to exit...\n'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment