-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (34 loc) · 1.53 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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var jsonParser = bodyParser.json();
var mongoose = require('mongoose');
var session = require('express-session');
var passport = require('passport');
var lists = require('./routers/lists');
var listsListId = require('./routers/listsListId');
var listsListIdItems = require('./routers/listsListIdItems');
var listsListIdItemsItemsId = require('./routers/listsListIdItemsItemsId');
var MongoURI = process.env.NODE_ENV === 'production' ? process.env.MONGODB_URI : 'mongodb://amituuush:[email protected]:25409/lyst'
mongoose.Promise = global.Promise;
mongoose.connect(MongoURI);
require('./config/passport')(passport);
app.use(session({secret: 'anystringoftext',
saveUninitialized: true,
resave: true}));
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
require('./app/routes.js')(app, passport);
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json())
// creates special route for handling static files (.js, .html, .css). These will automatically be served from public directory when something is requested
app.use(express.static(__dirname + '/public'));
var port = process.env.PORT || 7007;
// REGISTER OUR ROUTES ----------------------
// all of our routes will be prefixed with /api
app.use('/api', lists);
app.use('/api', listsListId);
app.use('/api', listsListIdItems);
app.use('/api', listsListIdItemsItemsId);
app.listen(port);
console.log('Magic happens on port ' + port);