-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (41 loc) · 1.42 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'),
port = process.env.PORT || 3000,
app = express(),
session = require('express-session'),
methodOverride = require('method-override'),
mongoUri = process.env.MONGOLAB_URI || 'mongodb://localhost/yearbook_app',
passport = require('passport');
mongoose.connect(mongoUri);
//Express
app.use(express.static('public'));
// require('./config/passport')(passport);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser());
app.use(bodyParser.json());
//Passport Reqs
app.use(session({ secret: 'secret-session' }));
app.use(passport.initialize());
app.use(passport.session());
app.use(methodOverride(function(req, res){
if (req.body && typeof req.body === 'object' && '_method' in req.body) {
var method = req.body._method;
delete req.body._method;
return method;
}
}));
//Routes
var usersController = require("./controllers/usersController");
var quotesController = require("./controllers/quotesController");
require("./config/passport.js")(passport);
app.use("/users", usersController);
app.use("/quotes", quotesController)
app.get("/", function(req, res){
res.redirect("/users");
});
mongoose.connection.once('open', function() {
app.listen(port, function() {
console.log('Running on port ' + port);
});
})