-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
56 lines (47 loc) · 1.58 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
const KEY = 'bdqueimadas.sid';
var express = require('express'),
path = require('path'),
load = require('express-load'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
app = express(),
server = require('http').Server(app),
fs = require('fs'),
cookieParser = require('cookie-parser'),
session = require('express-session'),
i18n = require( "i18n" ),
compression = require('compression');
var applicationConfigurations = JSON.parse(fs.readFileSync(path.join(__dirname, './configurations/Application.json'), 'utf8'));
BASE_URL = applicationConfigurations.BaseUrl;
app.use(compression());
app.use(cookieParser());
app.use(session({
secret: KEY,
name: "BDQueimadas",
resave: false,
saveUninitialized: false
}));
// Setting internationalization
i18n.configure({
locales : ["pt", "en", "es"],
directory : __dirname + "/locales",
objectNotation: true
});
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(i18n.init);
app.use(bodyParser.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
app.use(methodOverride('_method'));
app.use(BASE_URL, express.static(path.join(__dirname, 'public')));
app.use(require('connect-flash')());
app.use(function(req, res, next) {
var match = req.url.match(/^\/([A-Z]{2})([\/\?].*)?$/i);
if(match) {
req.lang = match[1];
req.url = match[2] || '/';
if(req.lang !== undefined && (req.lang === 'es' || req.lang === 'en')) res.setLocale(req.lang);
}
next();
});
module.exports = app;