-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (34 loc) · 1.26 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
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var beerController = require('./controllers/beer');
var userController = require('./controllers/user');
var passport = require('passport');
var authController = require('./controllers/auth');
mongoose.connect('mongodb://localhost/beerlocker', function (err) {
if (err) {
console.log('connection error', err);
} else {
console.log('connection successful');
}
});
var app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(passport.initialize());
var router = express.Router();
router.route('/beers')
.post(authController.isAuthenticated, beerController.postBeers)
.get(authController.isAuthenticated, beerController.getBeers);
router.route('/beers/:beer_id')
.get(authController.isAuthenticated, beerController.getBeer)
.put(authController.isAuthenticated, beerController.putBeer)
.delete(authController.isAuthenticated, beerController.deleteBeer);
router.route('/users')
.post(userController.postUsers)
.get(authController.isAuthenticated, userController.getUsers);
app.use('/api', router);
var port = process.env.PORT || 3000;
app.listen(port);
console.log('Insert beer on port ' + port);