-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
45 lines (38 loc) · 1.36 KB
/
app.js
File metadata and controls
45 lines (38 loc) · 1.36 KB
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
44
45
"use strict";
require('dotenv').load();
// Main starting point of the application
const express = require('express');
const http = require('http');
const bodyParser = require('body-parser'); // parse requests to JSON
const methodOverride = require('method-override');
const logger = require('morgan'); // log-in incoming requests framework
const app = express();
const path = require('path');
const fs = require('fs');
const router = require('./router');
const cors = require('cors');
const errorHandler = require('errorhandler');
// create a write stream (in append mode)
const accessLogStream = fs.createWriteStream(__dirname + '/access.log',{flags: 'a'});
// App Setup - middleware
app.set('port', process.env.PORT || 3001);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.engine('html', require('ejs').renderFile);
app.use(logger('dev'));
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
app.use(cors()); // accept all requests
// development only
if ('development' == app.get('env')) {
app.use(logger('combined', {stream: accessLogStream}));
app.use(errorHandler());
}
router(app);
http.createServer(app).listen(app.get('port'), '0.0.0.0', function() {
console.log('Express server listening on port ' + app.get('port'));
});