-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
33 lines (27 loc) · 904 Bytes
/
app.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
/* Requires */
var http = require( "http" );
var fs = require( "fs" );
var path = require( "path" );
var express = require( "express" );
var morgan = require( "morgan" );
const app = express();
/* Set */
app.set( "views", path.resolve( __dirname, "views" ) );
app.set( "view_engine", "ejs" );
/* Logger */
app.use( morgan( "combined" ) );
/* Routing for "/" */
app.get( "/", function( req, res ){
res.render( "index.ejs", { ip: req.connection.remoteAddress.substring( 7 ),
port: req.connection.remotePort } );
});
/* Serve static files */
app.use( express.static( path.join( __dirname, "static" ) ) );
/* Return 404 on error */
app.use( function( req, res ){
res.status( 404 ).render( "404.ejs" );
});
/* Create server */
app.listen( process.env.PORT || 8000, function(){
console.log( `Server is ready on port ${ process.env.PORT || 8000 }. Go!!!` );
});