-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
74 lines (56 loc) · 1.96 KB
/
app.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
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const passport = require('passport');
const hbs = require('hbs');
const path = require('path');
const cookieParser = require('cookie-parser');
const event_routes = require('./routes/api/event_routes');
const profile_routes = require('./routes/api/profile_routes');
const user_routes = require('./routes/api/user_routes');
const unauthorized_routes = require('./routes/api/unauthorized_routes');
const organizer_routes = require('./routes/organizer_routes');
// passport config import
require('./config/passport-setup')(passport)
/****************
TODO:
3. Keys protection -- heroku enviroment variables
9. Edge Cases review
25. code validation ?
****************/
const app = express();
const PORT = process.env.PORT || 3000;
// mongoose connection
mongoose.connect('mongodb://admin:admin123@ds231941.mlab.com:31941/univent' , { useNewUrlParser: true }).then(() => console.log('Database Connected'));
mongoose.Promise = global.Promise;
/* FINAL PROD_version : require('./config/connection.js')(); */
// passport init
app.use(passport.initialize());
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(user, done) {
done(null, user);
});
// handlebars cconfig
app.set('view engine', 'hbs');
app.set('views',path.join(__dirname, 'views'));
//static files
app.use(express.static(path.join(__dirname, 'static')));
// body-parser middleware
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(cookieParser());
// routes
app.use('/api/user', user_routes);
app.use('/api/event', event_routes);
app.use('/api/profile', profile_routes);
app.use('/api/unauthorized', unauthorized_routes);
app.use('/organizer', organizer_routes);
// home-route
app.get('/', (req,res) => {
res.render('index', {a : 'test'})
});
app.listen(PORT, () => {
console.log(`Sever running on PORT : ${PORT}`);
});