-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
48 lines (39 loc) · 1.21 KB
/
index.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
const express = require('express');
const bodyParser = require('body-parser');
const passport = require('passport');
const mongoose = require('mongoose');
const session = require('express-session');
global.hash = '3cf724f3-0f10-4c16-aabf-4031b51a05ef';
mongoose.connect(`mongodb://localhost:27017/geomar`,
{
useUnifiedTopology: true,
useNewUrlParser: true,
});
mongoose.connection.on('connected', () => {
console.log('Connected to Database ');
});
mongoose.connection.on('error', (err) => {
console.log(`Database error ${err}`);
});
mongoose.Promise = global.Promise;
const app = express();
const port = 80
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(session({
store: global.sessionStore, secret: global.hash, cookie: {
maxAge: 30 * 24 * 60 * 60 * 1000
}
}));
app.use(passport.initialize());
app.use(passport.session());
require('./src/middlewares/auth')(passport);
app.use('/app', require('./src/routes/app')(passport));
app.use('/login', require('./src/routes/login')(passport));
app.use('/logout', (req, res) => {
req.session.destroy();
res.redirect('/app');
});
app.listen(port, () => {
console.log(`Running on ${port}`)
})