-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
32 lines (26 loc) · 1.05 KB
/
server.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
console.log(" *** Server startup *** ");
global.ROOT_DIR = __dirname;
console.log(" - loading express");
var express = require('express');
var app = express();
console.log(" - loading path");
var path = require("path");
console.log(" - loading morgan");
var morgan = require('morgan');
console.log(" - loading body-parser");
var bodyParser = require('body-parser');
require(global.ROOT_DIR + '/server/walkDir');
app.set('views', global.ROOT_DIR + '/views');
app.set('view engine', 'pug');
app.use(bodyParser.urlencoded({ extended: false })); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
// Routes
console.log(" - loading routes");
app.use(express.static(path.join(global.ROOT_DIR, 'public'))); // serving static files
require(global.ROOT_DIR + '/server/routes')(app); // non-direct routes
app.use(morgan('dev')); // output requests to console
process.env.port = (process.env.port || 8080);
// launch server
app.listen(process.env.port, function () {
console.log('Server listening on port ' + process.env.port);
});