-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (29 loc) · 889 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
34
35
36
37
38
39
40
var express = require('express');
var mustacheExpress = require('mustache-express');
var calculatorController = require('./controllers/bmi_calculator');
var app = express();
// setup ports
var server_port = process.env.PORT || 5000;
app.engine('mustache', mustacheExpress(__dirname + '/views/partials'));
app.set('view engine', 'mustache');
calculatorController(app);
//Serve static files
app.use('/assets', express.static('assets'));
app.use(function(req, res, next){
res.status(404);
// respond with html page
if (req.accepts('html')) {
res.render('404', { url: req.url });
return;
}
// respond with json
if (req.accepts('json')) {
res.send({ error: 'Not found' });
return;
}
// default to plain-text. send()
res.type('txt').send('Not found');
});
app.listen(server_port, function(){
console.log( "Listening on port " + server_port );
});