www: Add i18n /en|fr/ urls
This commit is contained in:
parent
585e578e48
commit
4bfa6cfe16
44
app.js
44
app.js
@ -24,14 +24,14 @@ app.use(cookieParser());
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
const sess = {
|
||||
secret: 'keyboard cat',
|
||||
resave: true,
|
||||
saveUninitialized: true
|
||||
secret: 'keyboard cat',
|
||||
resave: true,
|
||||
saveUninitialized: true
|
||||
}
|
||||
|
||||
if (app.get('env') === 'production') {
|
||||
app.set('trust proxy', 1); // trust first proxy
|
||||
sess.cookie.secure = true; // serve secure cookies
|
||||
app.set('trust proxy', 1); // trust first proxy
|
||||
sess.cookie.secure = true; // serve secure cookies
|
||||
}
|
||||
|
||||
app.use(session(sess));
|
||||
@ -42,17 +42,31 @@ i18n.expressBind(app, {
|
||||
cookieName: 'locale'
|
||||
});
|
||||
|
||||
app.use('/dist/leaflet', express.static('node_modules/leaflet/dist'));
|
||||
app.use('/dist/feather', express.static('node_modules/feather-icons/dist'));
|
||||
app.use('/dist/axios', express.static('node_modules/axios/dist'));
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
app.use(function (req, res, next) {
|
||||
req.i18n.setLocaleFromQuery();
|
||||
req.i18n.setLocaleFromCookie();
|
||||
next();
|
||||
});
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
app.all('*', function(req, res, next) {
|
||||
// set locale
|
||||
var rxLocale = /^\/(fr|en)/i;
|
||||
if(rxLocale.test(req.url)){
|
||||
const arr = rxLocale.exec(req.url);
|
||||
const locale=arr[1];
|
||||
req.i18n.setLocale(locale);
|
||||
} else {
|
||||
req.i18n.setLocale('en');
|
||||
}
|
||||
// add extra logic
|
||||
next();
|
||||
});
|
||||
|
||||
app.use('/dist/leaflet', express.static('node_modules/leaflet/dist'));
|
||||
app.use('/dist/feather', express.static('node_modules/feather-icons/dist'));
|
||||
app.use('/dist/axios', express.static('node_modules/axios/dist'));
|
||||
|
||||
app.use(function (req, res, next) {
|
||||
res.header('Access-Control-Allow-Origin', 'http://localhost:3000');
|
||||
res.header(
|
||||
'Access-Control-Allow-Headers',
|
||||
@ -65,16 +79,16 @@ app.use('/api/0', apiRouter);
|
||||
|
||||
const csrfProtection = csrf({ cookie: true });
|
||||
app.use(csrfProtection);
|
||||
app.use('/', indexRouter);
|
||||
app.use('/auth', authRouter);
|
||||
app.use(/\/(fr|en)/i, indexRouter);
|
||||
app.use(/\/(fr|en)\/auth/i, authRouter);
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function(req, res, next) {
|
||||
app.use(function (req, res, next) {
|
||||
next(createError(404));
|
||||
});
|
||||
|
||||
// error handler
|
||||
app.use(function(err, req, res, next) {
|
||||
app.use(function (err, req, res, next) {
|
||||
// set locals, only providing error in development
|
||||
res.locals.message = err.message;
|
||||
res.locals.error = req.app.get('env') === 'development' ? err : {};
|
||||
|
@ -1 +1,4 @@
|
||||
{}
|
||||
{
|
||||
"Game": "Game",
|
||||
"About": "About"
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"Home": "Home",
|
||||
"About": "About"
|
||||
"Home": "Inicio",
|
||||
"About": "Acerca de",
|
||||
}
|
Loading…
Reference in New Issue
Block a user