-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (53 loc) · 1.76 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const express = require('express')
const path = require('path')
require("dotenv").config();
const database = require('./config/database')
const systemConfig = require('./config/system')
const routeAdmin = require("./routes/admin/index.route")
const routeClient = require("./routes/client/index.route")
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 moment = require("moment");
require('events').EventEmitter.defaultMaxListeners = Infinity;
const http = require('http');
const { Server } = require("socket.io");
database.connect()
const app = express()
const port = process.env.PORT
app.set("views", `${__dirname}/views`);
app.set('view engine', 'pug')
// SocketIO
const server = http.createServer(app);
const io = new Server(server);
global._io = io;
// End SocketIO
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
// Flash
app.use(cookieParser('HKAHLALASGAD'));
app.use(session({ cookie: { maxAge: 60000 } }));
app.use(flash());
/* New Route to the TinyMCE Node module */
app.use('/tinymce', express.static(path.join(__dirname, 'node_modules', 'tinymce')));
// Method override
app.use(methodOverride('_method'))
// App locals variables
app.locals.prefixAdmin = systemConfig.prefixAdmin
app.locals.moment = moment
app.use(express.static(`${__dirname}/public`));
// Routes
routeClient(app)
routeAdmin(app)
app.get('*', (req, res) => {
res.render('client/pages/errors/404', {
pageTitle: '404 Not Found'
})
})
server.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})