-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb_server.js
More file actions
35 lines (26 loc) · 802 Bytes
/
web_server.js
File metadata and controls
35 lines (26 loc) · 802 Bytes
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
//
'use strict';
var url = require( 'url' );
var path = require( 'path' );
var fs = require( 'fs' );
var http = require( 'http' );
var express = require( 'express' );
var args = require( 'minimist' )( process.argv.slice( 2 ), { string: [ 'p', 'port' ] } );
var app = express();
console.log( typeof args.p, typeof args.port, typeof 8080 );
var port = args.p || args.port || 8080;
// add in cli port, hostname, etc
function log( req, res, next ) {
req.time = Date.now();
console.log( req.time + ' ' + req.method + ' ' + req.url );
next();
}
app.use( log );
app.use( express.static( __dirname + '/' ) );
app.get( '/', function( req, res ){
res.send( 'get received' );
} );
app.listen( port, function () {
console.log("Example app listening on port " + port); // fix, real port
//host?
} );