-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (37 loc) · 1.57 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
var express = require('express'),
bodyParser = require('body-parser'),
mongoose = require('mongoose'),
fitnessController = require('./controllers/fitness-controller'),
authController = require('./controllers/auth-controller'),
userController = require('./controllers/user-controller');
mongoose.connect('mongodb://localhost/testfitness');
var app = express();
//configure the server
// Accept application/json
app.use(bodyParser.json());
//accept xml
app.use(bodyParser.urlencoded({
extended: true
}));
//define a place for our CSS and JS files
app.use(express.static(__dirname + '/public'));
//register our engine as .html so we can have .html pages
app.engine('.html', require('ejs').__express);
//define our views folder
app.set('views', __dirname + '/views');
//set our view engine to HTML
app.set('view engine', 'html');
app.get('/', function(req, res) {
res.render('index');
});
app.put('/login', authController.login);
app.get('/logout', authController.logout);
app.put('/adduser', userController.addUser);
app.put('/settings', authController.authed, userController.saveSettings);
app.get('/settings', authController.authed, userController.loadSettings);
app.get('/bodyfat', authController.authed, fitnessController.getAllBodyFat);
app.put('/bodyfat', authController.authed, fitnessController.addBodyFat);
app.get('/bodyfat/:date', authController.authed, fitnessController.getSingleBodyFat);
app.put('/bodyfat/:date', authController.authed, fitnessController.updateSingleBodyFat);
app.listen(3000);
console.log('Listening on port 3000...');