This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.js
76 lines (55 loc) · 1.83 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
'use strict';
const express = require('express');
const enrouten = require('express-enrouten');
const app = express();
const config = require('config');
const compression = require('compression');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const path = require('path');
const configureProxies = require('./lib/booting/proxies');
const configureRedirects = require('./lib/booting/redirects');
const configureNunjucks = require('./lib/booting/nunjucks');
const configureSass = require('./lib/booting/compileSass');
const configureErrorPages = require('./lib/booting/errorPages');
const { redirectToLanguage } = require('./lib/translate');
module.exports = async () => {
// Express setup
app.use(logger('dev'));
app.use(compression());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.disable('x-powered-by');
// Nunjucks
configureNunjucks(app);
// Defaults
app.locals = {
...app.locals,
...config.get('locals'),
locales: config.get('locales')
};
// SASS compliation
await configureSass(app);
// Setup routes
configureProxies(express, app);
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, res) => {
redirectToLanguage(req, res, '/');
});
app.use('/:lang', (req, res, next) => {
req.lang = req.params.lang;
next();
});
app.use('*', configureRedirects);
app.use('/:lang', enrouten({
directory: 'controllers'
}));
// Configure error pages
configureErrorPages(app);
console.log('App started with:');
console.log('- Node.js', process.version);
console.log(`- Started with NODE_ENV=${app.get('env')}`);
return app;
};