-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (26 loc) · 1008 Bytes
/
index.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
const express = require('express')
const bodyParser = require('body-parser');
const config = require('./src/config/app.config');
const apiRouter = require('./src/api.route');
const i18n = require('./src/i18n');
const { errorHandler } = require('./src/middleware');
const { NotFoundError } = require('./src/errors');
const { error } = require('./src/helpers/response.helper');
const MasterDB = require('./src/database/db');
const redisClient = require('./src/database/redis');
const { loadModels } = require('./src/models');
const app = express();
(async () => {
await MasterDB.init()
await redisClient.connect();
loadModels();
app.use(i18n.init);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/api/v1/', apiRouter);
app.use(errorHandler);
app.use((req, res) => error(req, res, new NotFoundError()));
app.listen(config.port, config.host, () => {
console.log(`Server listening on http://${config.host}:${config.port}`)
});
})()