forked from ygyash/dhwani-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (47 loc) · 1.44 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
// Initial Setup
var express=require("express");
var app=express();
var cors = require('cors');
var bodyParser=require("body-parser");
app.use(bodyParser.urlencoded({ extended: true }));
app.set("view engine","ejs");
var {secretKey} = require('./config.js');
app.use('/public', express.static('public'));
/**
* CORS middleware. This is important for letting the UI and APIs on separate domain.
*/
app.use(cors());
// Models
var User=require("./models/user.js");
var Slot=require("./models/slot.js");
// Passport
var passport=require("passport");
var localStrategy=require("passport-local");
app.use(require("express-session")({
secret: secretKey,
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new localStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
var mongoDB = require('./config.js').mongoDB;
// Enable data of user
app.use(function(req,res,next){
res.locals.currentUser=req.user;
next();
});
// Routes
var indexRoute=require("./routes/index.js");
var dashboardRoute=require("./routes/dashboard.js");
var notifRoute = require("./routes/notification.js");
var userRoute = require("./routes/userpage.js");
app.use(indexRoute);
app.use(dashboardRoute);
app.use(notifRoute);
app.use(userRoute);
app.listen(5000,function(){
console.log("Server Running on Local host 5000");
});