-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.js
60 lines (42 loc) · 1.9 KB
/
web.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
50
51
52
53
54
55
56
57
58
59
60
var express = require('express');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var session = require('cookie-session');
var mongoose = require('mongoose');
var jade = require('jade');
var passport = require('passport');
var flash = require('connect-flash');
var configDB = require('./config/database.js');
var app = express();
// configuration ===============================================================
var mongo = mongoose.connect(configDB.url); // connect to our database
require('./config/passport')(passport); // pass passport for configuration
var env = process.env.NODE_ENV || 'development';
if (env.indexOf('development') !== -1) {
console.log('here');
// set up our express application
app.use(logger('dev')); // log every request to the console
app.use(cookieParser()); // read cookies (needed for auth)
app.use(bodyParser()); // get information from html forms
app.use(bodyParser.json({ type: 'application/vnd.api+json' }))
app.use(function (req, res, next) {
console.log(req.body) // populated!
next()
})
app.set('views', __dirname + '/views');
app.set('view engine', 'jade'); // set up ejs for templating
// required for passport
app.use(session({ secret: 'ilovescotchscotchyscotchscotch' })); // session secret
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
}
// routes ======================================================================
require('./routes.js')(app, passport); // load our routes and pass in our app and fully configured passport
// Error 404
app.use(function(req, res, next){
res.setHeader('Content-Type', 'text/plain');
res.send(404, 'Cannot find page!');
});
app.listen(8080);