-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
64 lines (56 loc) · 1.79 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
const express = require('express');
const session = require('express-session');
const bodyParser = require('body-parser');
const compression = require('compression');
const config = require('./local-config');
const pkg = require ('./package.json');
const engine = require('ejs-mate');
const i18n = require('i18n-2');
const acceptLanguage = require('accept-language');
const socket = require('./socket');
const app = express();
const router = require('./routes');
const lang = require('./utils/lang');
const http = require('http').Server(app);
const io = require('socket.io').listen(http);
socket.listen(io);
acceptLanguage.languages(config.locales);
i18n.expressBind(app, {locales: config.locales});
app.locals.locals = require('./utils/locals');
app.engine('ejs', engine);
app.set('views',__dirname + '/views');
app.set('view engine', 'ejs');
if(config.env == 'prod'){
app.set('view cache', true);
app.set('x-powered-by', false);
app.use(compression());
}
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(session({
secret: config.secret,
resave: true,
saveUninitialized: true
})
);
app.use((req, res, next) => {
req.io = io;
next();
});
app.use(router.redirect);
app.use(lang.firstVisit);
app.use(lang.setLang);
for(let i = 1; i < config.locales.length; i++) {
app.use('/' + config.locales[i], router.routes);
app.use('/' + config.locales[i], router.pages);
}
app.use(router.routes);
app.use(router.pages);
for(let i = 1; i < config.locales.length; i++) {
app.use('/' + config.locales[i], router.errors);
}
app.use(router.errors);
http.listen(config.port, () => {
console.log(`Genuine.js ${pkg.version} on http://localhost:${config.port}`);
});