-
Notifications
You must be signed in to change notification settings - Fork 3
/
webapp.js
executable file
·66 lines (55 loc) · 1.62 KB
/
webapp.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var path = require('path');
var express = require('express');
var bodyParser = require('body-parser');
var session = require('express-session');
var flash = require('connect-flash');
var morgan = require('morgan');
var config = require('./config');
var scheduler = require('./scheduler');
var sassMiddleware = require('node-sass-middleware');
// Create Express web app
var app = express();
app.set('view engine', 'jade');
// Use morgan for HTTP request logging
app.use(morgan('combined'));
// Use Sass
app.use(
sassMiddleware({
src: __dirname + '/sass',
dest: __dirname + '/public',
debug: true,
})
);
// Serve static assets
app.use(express.static(path.join(__dirname, 'public')));
// Parse incoming form-encoded HTTP bodies
app.use(bodyParser.urlencoded({
extended: true
}));
// Create and manage HTTP sessions for all requests
app.use(session({
secret: config.secret,
resave: true,
saveUninitialized: true
}));
// Use connect-flash to persist informational messages across redirects
app.use(flash());
// Configure application routes
require('./controllers/router')(app);
// Handle 404
app.use(function (request, response, next) {
response.status(404);
response.sendFile(path.join(__dirname, 'public', '404.html'));
});
// Unhandled errors (500)
app.use(function(err, request, response, next) {
console.error('An application error has occurred:');
console.error(err);
console.error(err.stack);
response.status(500);
response.sendFile(path.join(__dirname, 'public', '500.html'));
});
// start the scheduler to send appointments
scheduler.start();
// Export Express app
module.exports = app;