-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
44 lines (36 loc) · 964 Bytes
/
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
const express = require('express');
const session = require('express-session')
const app = express();
const passport = require('./auth/mypassport')
const db = require('./db/models').db;
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(session({
secret: 'something that should not be shared',
resave: false,
saveUninitialized: true
}))
app.use(passport.initialize())
app.use(passport.session())
app.use('/api', require('./routes/index'));
app.get('/logout', (req, res) => {
req.logout()
res.redirect('/')
})
app.post('/login', passport.authenticate('local', {failureRedirect: '/'}), (req, res) => {
res.send({
success: true,
url: '/student/'
});
})
app.get('/student', (req, res, next) => {
if (!req.user) {
console.log("ABC")
return res.redirect('/');
}
next();
})
app.use(express.static(__dirname + '/public'));
app.listen(8888, () => {
console.log("Server Listening on port 8888");
})