-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
59 lines (50 loc) · 1.61 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
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const session = require('express-session')
const cookieParser = require('cookie-parser')
const auth = require('./routes/auth');
const mongoSessionStore = require('connect-mongo');
const middleware = require('./middleware/authJwt')
const userInfo = require('./routes/userInfo')
require('dotenv').config()
const options = {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
};
mongoose.connect(process.env.MONGO_URL, options);
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('connected to mongodb')
});
const app = express();
const port = process.env.PORT || 5000;
const MongoStore = mongoSessionStore(session)
app.use(cookieParser())
app.use(session({
name: 'uid',
secret: '39082mx92m20x9',
resave: true,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
cookie: {
httpOnly: true,
maxAge: 24 * 60 * 60 * 1000
}
}))
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }))
auth(app)
userInfo(app)
app.get('/api/getInfo', (req, res) => {
const data = [
{ id: 1, name: 'blue gilled fire', details: 'kills you painfully' },
{ id: 2, name: 'yello stripped zebra', details: "doesn't kill you" },
];
res.send(JSON.stringify(data));
});
app.listen(port, () => console.log(`Listening on port ${port}`));