-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
56 lines (48 loc) · 1.62 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
const express = require('express');
const app = express();
const cookieParser = require('cookie-parser')
const env = require('dotenv')
const session = require('express-session')
const passport = require('passport')
const flash = require('connect-flash')
const dbConnect = require('./config/database')
const router = require('./routers/routes');
// for passport facebook congif/passportFB
require('./utilities/passportFB')(passport)
//
const { notFoundHandler, errorHandler } = require('./middleware/common/errorHandler');
const { checkUser } = require('./middleware/common/AuthMiddleware')
env.config()
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.use(express.urlencoded({ extended: true, limit: '50mb' }));
app.use(express.json({ limit: '50mb' }));
// cookie parser
app.use(cookieParser(process.env.COOKIE_SECRET))
app.use(session({
secret: process.env.COOKIE_SECRET,
resave: false,
saveUninitialized: false,
// using flash message
// cookie: {maxAge: 1 },
// cookie: { httpOnly: true },
}))
app.use(passport.initialize());
app.use(passport.session());
// Check User
app.use(checkUser)
app.use(flash())
app.use(router);
// 404 not found
app.use(notFoundHandler)
// error handling
app.use(errorHandler)
// server
app.listen(process.env.PORT, async () => {
if (process.env.NODE_ENV === 'development') {
const onlyGroupbyNull = 'SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,"ONLY_FULL_GROUP_BY",""))';
await dbConnect.promise().execute(onlyGroupbyNull)
}
console.log(`Server Running http://localhost:${process.env.PORT}`);
});
// SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,"ONLY_FULL_GROUP_BY",""))