-
Notifications
You must be signed in to change notification settings - Fork 182
/
app.js
43 lines (35 loc) · 1.3 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
import express from 'express';
import mongoose from 'mongoose';
import redis from 'redis';
import config from './config/config';
import expressConfig from './frameworks/webserver/express';
import routes from './frameworks/webserver/routes';
import serverConfig from './frameworks/webserver/server';
import mongoDbConnection from './frameworks/database/mongoDB/connection';
import redisConnection from './frameworks/database/redis/connection';
// middlewares
import errorHandlingMiddleware from './frameworks/webserver/middlewares/errorHandlingMiddleware';
const app = express();
const server = require('http').createServer(app);
// express.js configuration (middlewares etc.)
expressConfig(app);
// server configuration and start
serverConfig(app, mongoose, server, config).startServer();
// DB configuration and connection create
mongoDbConnection(mongoose, config, {
autoIndex: false,
useCreateIndex: true,
useNewUrlParser: true,
autoReconnect: true,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 10000,
keepAlive: 120,
connectTimeoutMS: 1000
}).connectToMongo();
const redisClient = redisConnection(redis, config).createRedisClient();
// routes for each endpoint
routes(app, express, redisClient);
// error handling middleware
app.use(errorHandlingMiddleware);
// Expose app
export default app;