-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (41 loc) · 1.48 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
const express = require("express")
const dotenv = require("dotenv");
const routeClient = require("./routers/client/index.route");
const routeAdmin = require("./routers/admin/index.route")
const systemConfig = require("./config/system.js")
const database = require('./config/database.js')
const methodOverride = require('method-override');
const bodyParser = require('body-parser');
const flash = require('express-flash');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const path = require('path');
const moment = require("moment")
dotenv.config();
const app = express()
database.connect();
app.use(express.static(`${__dirname}/public`))
//ghi đè pt form
app.use(methodOverride('_method'));
//flash hien thi thong bao sao khi thuc thi
app.use(cookieParser('QUIMAIPHUC'));
app.use(session({ cookie: { maxAge: 60000 }}));
app.use(flash());
//End flash hiển thị thông báo
app.use(bodyParser.urlencoded({ extended: false }));
app.set('view engine', 'pug');
//đi vào thẳng đường dẫn views public
app.set('views', `${__dirname}/views`)
//set locals biến dùng trong all file pug
app.locals.prefixAdmin = systemConfig.prefixAdmin;
app.locals.moment = moment
app.use('/tinymce', express.static(path.join(__dirname, 'node_modules', 'tinymce')));
const port = process.env.PORT
routeClient(app)
routeAdmin(app)
app.get("*", (req, res) =>{
res.render("client/pages/error/404")
})
app.listen(port, () => {
console.log(`App listening on port ${port}`)
});