-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (63 loc) · 1.65 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'Use Strict';
// npm packages
import express from 'express';
import path from 'path';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import logger from 'morgan';
import dotenv from 'dotenv';
import mongoose from 'mongoose';
import url from 'url';
import passportFile from './config/passport.js'
import session from 'express-session';
import passport from 'passport';
import MS from 'express-mongoose-store';
import * as userAgent from 'express-useragent';
// routers
import router from './routes/index.js';
// statements
dotenv.config()
passportFile(passport)
const store = MS(session, mongoose)
// constants
const app = express();
const port = process.env.PORT
const __filename = url.fileURLToPath(
import.meta.url);
const __dirname = path.dirname(__filename);
// express middlewares
if (process.env.ENV == 'dev') {
app.use(logger(process.env.ENV));
}
app.use(express.json({
limit: '10mb',
extended: true
}));
app.use(express.urlencoded({
extended: false
}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, '/public')));
app.use(session({
secret: process.env.SECRET,
resave: false,
saveUninitialized: false,
store: new store({
ttl: 63113904000
})
}));
app.use(passport.initialize());
app.use(passport.session());
app.set('views', './views');
app.set('view engine', 'ejs');
app.use(userAgent.express())
// routes
app.use('/', router);
mongoose.connect(process.env.MONGO, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
})
// listen on port
app.listen(port, console.log(`Started on port: http://localhost:${port}`));