-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (37 loc) · 1005 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var config = {
port: 80,
folder: 'www',
version: '1.0.0',
CB : function() {
console.log('Ultra simple web server', config.version)
console.log('Listening on', config.port)
console.log('Serving', config.folder)
}
}
var express = require("express")
var path = require('path')
var app = express()
config.folder = path.join(__dirname, '../..',config.folder)
// Simple logger...
function log(req, msg) {
console.log(`${new Date().toISOString()} ${req.ip} ${msg}`)
}
function listen (userPort, userFolder, userCb) {
if (userFolder) config.folder = path.join(__dirname, userFolder)
if (userPort) config.port = userPort
if (userCb) config.CB = userCb
// Static default routes...
app.get(/^(.+)$/, function(req, res){
log(req, req.params[0])
res.sendFile( req.params[0], {root: config.folder} )
})
app.listen(config.port, config.CB)
return app
}
// Export a listen function...
module.exports = {
listen: listen,
log: log,
app: app,
express: express
}