-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
46 lines (37 loc) · 1.04 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
const express = require('express');
const logger = require('morgan');
const bodyParser = require('body-parser');
const i18n = require('i18n');
const expressValidator = require('express-validator');
const routes = require('./app/routes');
const cors = require('cors');
const { init } = require('./app/middlewares/authMiddleware');
let database = require('./db/dataBase');
const app = express();
app.listen(3000);
init(app);
database.init();
//Set locale
i18n.configure({
locales:['en', 'es'],
directory: __dirname + '/locales'
});
app.use(i18n.init);
// use it before all route definitions
app.use(cors({origin: 'http://localhost:4200'}));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(expressValidator());
routes(app);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.send(err);
});
module.exports = app;