-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
84 lines (50 loc) · 1.92 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const express = require('express')
const logger = require('morgan')
const dotenv = require('dotenv');
const session = require('express-session');
const expressLayouts = require('express-ejs-layouts');
const cookieParser = require('cookie-parser');
const path = require('path');
const mongoose = require('mongoose');
const nocache = require('nocache');
const swal = require('sweetalert2')
const app = express();
dotenv.config({path:'./.env'})
//Session
app.use(session({
secret:process.env.SESSION_SECRET_KEY ,
resave: false,
saveUninitialized: true,
cookie: { secure: false, httpOnly: true, maxAge: 24 * 60 * 60 * 1000 } // set cookie options
}));
const db = process.env.DATABASE_LOCAL;
mongoose.connect(db,{
useNewUrlParser:true,
useUnifiedTopology: true,
}).then(()=>console.log("mongodb connected"))
.catch(err=>console.log(err.message))
// //connecting to database
app.use(logger('dev'))
//Body parser
app.use(express.json())
app.use(express.urlencoded({extended:false}));
//cookie parser
app.use(cookieParser());
// Disable caching of responses
app.use(nocache());
// Enable layout templates using express-ejs-layouts
app.use(expressLayouts);
app.use(express.static('public'));
app.set('layout', 'layouts/layout');
// Set up the views directory and view engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// Serve static files from the public directory
app.use(express.static('assets'));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/',require('./routes/user'))
app.use('/admin',require('./routes/admin'))
const port = process.env.PORT ;
app.listen(port,()=>{
console.log(`server listening to http://localhost:${port}`);
});