forked from SwahiliBox/CodeChallenge1Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·81 lines (70 loc) · 2.64 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var express = require('express');
var nodemailer = require('nodemailer');
var app = express();
var port = process.env.PORT || 3000;
//initialize required modules for the app
var passport = require('passport');
var session = require('express-session');
var bodyparser = require('body-parser');
var morgan = require('morgan');
var path = require('path');
var mongoose = require('mongoose');
var ejs = require('ejs');
var engine = require('ejs-mate');
var mongodb = require('mongodb');
var exphbs = require('express-handlebars');
var expressvalidator = require('express-validator');
var morgan = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var methodOverride = require('method-override');
var flash = require('connect-flash');
var cors = require('cors');
var mongostore = require('connect-mongo')(session);
var rsvp = require('./app/models/rsvp');
//connect to mongo database
var configDB = require('./config/database.js');
mongoose.connect(configDB.url);
//require passport for authentication
require('./config/passport.js')(passport);
//use required modules
app.use(morgan('dev'));
app.use(methodOverride());
/* app.use(express.static(path.join(__dirname, 'views'))); */
app.use(express.static(__dirname + '/public'));
app.use('/bower_components', express.static(__dirname + '/bower_components'));
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(session({secret:'anystringoftext',
saveUninitialized:true,
resave:false
}));
/*
this middleware is used to make the user object accessible
throughout all our routes
*/
app.use(function(req, res, next){
res.locals.user = req.user;
next();
});
app.use(cors());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
require('./config/passport')(passport);
app.set('view engine', 'html');
app.engine('ejs', engine);
app.set('view engine', 'ejs');
app.use(passport.initialize());
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
require('./config/routes/rsvp')(app, passport);
require('./config/routes/user')(app, passport);
require('./config/routes/events')(app, passport);
require('./config/routes/main')(app, passport);
app.listen(port);
console.log('Server running on localhost: port ' + port);