-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (36 loc) · 1.54 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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var ingredients = require('./app/ingredient-routes');
var drinks = require('./app/drink-routes');
var db = require('./config/db');
var port = process.env.PORT || 8080;
var mongoose = require('mongoose');
mongoose.connect(db.url);
mongoose.Promise = require('q').Promise;
// mongoose.connect('mongodb://colin:pw@apollo.modulusmongo.net:27017/y3Pyhoxy');
app.use(bodyParser.json());
app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride('X-HTTP-Method-Override'));
app.use(express.static(__dirname + '/public'));
app.get('/api/ingredients', ingredients.list);
app.post('/api/ingredients', ingredients.create);
app.get('/api/ingredients/:ingredient_id', ingredients.show);
app.put('/api/ingredients/:ingredient_id', ingredients.update);
app.delete('/api/ingredients/:ingredient_id', ingredients.delete);
app.post('/api/ingredients_seed', ingredients.seed);
app.get('/api/drinks', drinks.list);
app.post('/api/drinks', drinks.create);
app.get('/api/drinks/:drink_id', drinks.show);
app.put('/api/drinks/:drink_id', drinks.update);
app.delete('/api/drinks/:drink_id', drinks.delete);
app.delete('/api/drinks', drinks.drop);
app.post('/api/drinks_seed', drinks.seed);
app.get('*', function(req, res) {
res.sendfile('./public/views/index.html');
});
app.listen(port);
console.log('Magic happenin on ' + port);
exports = module.exports = app;