-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
57 lines (46 loc) · 1.85 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
//Loading Modules
const express = require('express');
const morgan = require('morgan');
const bodyparser = require('body-parser');
const path = require('path');
const session = require('express-session');
const cookie = require('cookie-parser');
const connectdb = require('./server/database/connection');
// const RedisStore = require('connect-redis')(session);
// const Redis = require('ioredis');
const app = express();
require('dotenv').config();
const PORT = process.env.PORT || 8000;
//log requests
app.use(morgan('tiny'));
//set engine name
app.set("view engine", "ejs")
//json parser
app.use(express.json())
//use body parser
app.use(bodyparser.urlencoded({extended:true}))
app.use(bodyparser.json())
//use static files
app.use(express.static(path.resolve(__dirname, 'assest')));
app.use('/uploads', express.static(path.resolve(__dirname, 'assest/uploads')));
app.use('/js', express.static(path.resolve(__dirname, 'assest/js')));
app.use('/css', express.static(path.resolve(__dirname, 'assest/css')));
app.use('/css', express.static(path.resolve(__dirname, 'node_modules/bootstrap/dist/css')));
app.use('/js', express.static(path.resolve(__dirname, 'node_modules/bootstrap/dist/js')));
app.use('/js', express.static(path.resolve(__dirname, 'node_modules/jquery/dist')));
// const redisClient = new Redis();
//Configure session middleware
app.use(session({
// store: new RedisStore({ client: redisClient }),
secret: 'mynewsession',
resave: false,
saveUninitialized: false,
cookie: {
secure: false, // if true only transmit cookie over https
httpOnly: false, // if true prevent client side JS from reading the cookie
maxAge: 1000 * 60 * 60 * 24 // session max age in miliseconds
}
}))
//passing root variable
app.use('/', require('./server/route'));
app.listen(PORT, () => console.log("listening on port available",PORT));