feat: i18n middleware

feat: i18n configuration.
feat: i18n with tenancy.
This commit is contained in:
Ahmed Bouhuolia
2020-09-05 17:31:39 +02:00
parent 79b7a02f85
commit d35b124178
14 changed files with 122 additions and 34 deletions

View File

@@ -2,20 +2,42 @@ import express from 'express';
import helmet from 'helmet';
import boom from 'express-boom';
import errorHandler from 'errorhandler';
import i18n from 'i18n';
import fileUpload from 'express-fileupload';
import i18n from 'i18n';
import routes from '@/http';
import config from '@/../config/config';
export default ({ app }) => {
// Express configuration.
app.set('port', 3000);
// Helmet helps you secure your Express apps by setting various HTTP headers.
app.use(helmet());
// Allow to full error stack traces and internal details
app.use(errorHandler());
// Boom response objects.
app.use(boom());
// Parses both json and urlencoded.
app.use(express.json());
// Handle multi-media requests.
app.use(fileUpload({
createParentPath: true,
}));
routes(app);
// Initialize i18n node.
app.use(i18n.init)
// Prefix all application routes.
app.use(config.api.prefix, routes());
// catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('Not Found');
err['status'] = 404;
next(err);
})
};