-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
105 lines (83 loc) · 2.3 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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var express = require('express');
var engine = require('ejs-locals');
var app = express();
var fs = require('fs');
var moment = require('moment');
var bodyParser = require('body-parser');
var sassMiddleware = require('node-sass-middleware');
var cookieParser = require('cookie-parser');
var webapi = require('./webapi').router;
var api = require('./api');
//Housekeeping
app.engine('ejs', engine);
app.set('views',__dirname + '/views');
app.set('view engine', 'ejs');
app.set('view options', { layout:'views/layouts/layout.ejs' });
app.use(cookieParser());
app.use(bodyParser.json());
app.use('/public', express.static('public'));
app.use(
sassMiddleware({
src: __dirname + '/sass', //where the sass files are
dest: __dirname, //where css should go
debug: false
})
);
process.on('uncaughtException', function (err) {
console.log("Error: " + err);
});
//Real Pages
app.get('/', function (req, res) {
res.render('pages/schedpage', {
"title": '',
});
});
app.get('/about', function (req, res) {
res.render('pages/about', {
"title": "About",
});
});
// app.get('/help', function (req, res) {
// var title = "Help";
// var content = "<p>Instructions to come.</p>";
// res.render('pages/stdpage', {
// "title": title,
// "content": content
// });
// });
//Web API Controller Commands
app.use('/webapi', webapi);
//External API Commands
app.use('/api', api);
//Errors
app.use(function(req, res, next){
res.status(404);
res.format({
html: function () {
res.render('pages/stdpage',{
'title':"Error 404",
'content':'Whoops! Page not found. Sorry about that.'
});
},
json: function () {
res.json({ error: 'Not found' })
},
default: function () {
res.type('txt').send('Not found')
}
})
});
app.use(function(err, req, res, next){
console.log(err);
res.status(err.status || 500);
res.render('pages/stdpage',{
'title':"Error "+err,
'content':'An error occurred. Check the URL or click around.'
});
});
//Start Server
var server = app.listen(process.env.PORT || 8080, function () {
var host = server.address().address
var port = server.address().port
console.log("API listening at http://%s:%s", host, port)
});