-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
79 lines (58 loc) · 1.56 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
const express = require('express');
const session = require('express-session');
var bodyParser = require("body-parser");
const cors = require('cors');
const login = require('./routes/login');
const register = require('./routes/register');
const addevent = require('./routes/form');
const eventlist= require('./routes/event');
const deleteevent = require('./routes/delete');
const logout = require('./routes/logout');
const app = express();
// port no. of server
const port = 5000;
const whiltelist = ['http://localhost:3000'];
const corsOption = {
credentails: true,
origin: function(origin, callback) {
if(whiltelist.indexOf(origin) !== -1 || !origin) {
callback(null, true);
}
else {
callback(new Error('Not allowed By CORS'))
}
},credentials: true
}
app.use(bodyParser.json());
app.use(cors(corsOption));
app.use(session({
key: 'passiskey',
secret: 'passmusrbesecret',
saveUninitialized: true,
resave: 'false'
}))
const aunt = (req, res, next) => {
if(req.session.email) {
next();
}
}
const logt = (req, res, next) => {
if(req.session.email) {
req.session.email = null;
next();
}
else {
res.status(401);
}
}
// import routes
app.use('/login', login);
app.use('/register', register);
app.use('/addevent', aunt,addevent);
app.use('/eventlist', aunt, eventlist);
app.use('/deleteevent', deleteevent);
app.use('/logout',logt, logout);
app.listen(port, () => {
console.log('server is running on port' + port);
})
// killall node