-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
81 lines (66 loc) · 2.43 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
75
76
77
78
79
80
81
var express = require('express');
var ejs = require('ejs');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var path = require('path');
var passport = require('passport');
const cookieParser = require('cookie-parser');
const session = require('express-session');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }))
app.use(session({secret: 'keyboard cat', resave: false, saveUninitialized: false}));
app.use(cookieParser());
//Passport Initialization
app.use(passport.initialize());
app.use(passport.session());
// app.use(function(req, res, next) {
// var allowedOrigins = ['http://127.0.0.1:3000', 'http://elementsculmyca.com/', 'http://admin.elementsculmyca.com/', 'https://culmyca19.herokuapp.com'];
// var origin = req.headers.origin;
// if(allowedOrigins.indexOf(origin) > -1){
// res.setHeader('Access-Control-Allow-Origin', origin);
// }
// //res.header('Access-Control-Allow-Origin', 'http://127.0.0.1:8020');
// res.header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE');
// res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
// res.header('Access-Control-Allow-Credentials', true);
// return next();
// });
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();
});
// Mongoose Connection
mongoose.connect('mongodb://namansachdeva:namansachdeva12@ds159204.mlab.com:59204/culmyca19',{ useNewUrlParser: true })
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error: '));
//Show that our db is succesfully Connected
db.once('open', function(){
console.log("Connected to Mongo Lab: ");
});
// Express session
app.use(
session({
secret: 'secret',
resave: true,
saveUninitialized: true
})
);
// Passport middleware
app.use(passport.initialize());
app.use(passport.session());
//Set path for the Routes
var routes = require('./routes/user');
var routes_club = require('./routes/club');
//Setting the views
app.set('views', path.join(__dirname,'views'));
app.set('view engine', 'ejs');
// Set Static Folder
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/club',routes_club);
var port = process.env.PORT || 3000
app.listen(port, function() {
console.log("App is running on port " + port);
});