-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
52 lines (41 loc) · 1.09 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
require('dotenv').config();
const express = require('express');
const expressLayout = require('express-ejs-layouts');
const methodOverride = require('method-override');
const session = require('express-session');
const connectDB = require('./server/config/db');
const app = express();
const port = process.env.PORT || 5000;
// Connect to Database
connectDB();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(methodOverride('_method'));
// Static Files
app.use(express.static('public'));
// Express Session
app.use(
session({
secret: 'secret',
resave: false,
saveUninitialized: true,
cookie: {
maxAge: 1000 * 60 * 60 * 24 * 7, // 1 week
}
})
);
// Flash Messages
// app.use(flash({ sessionKeyName: 'flashMessage' }));
// Templating Engine
app.use(expressLayout);
app.set('layout', './layouts/main');
app.set('view engine', 'ejs');
// Routes
app.use('/', require('./server/routes/customer'))
// Handle 404
app.get('*', (req, res) => {
res.status(404).render('404');
});
app.listen(port, ()=> {
console.log(`App listeing on port ${port}`)
});