-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
47 lines (44 loc) · 1.64 KB
/
Copy pathapp.js
File metadata and controls
47 lines (44 loc) · 1.64 KB
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
47
const express = require('express');
const path = require('path');
const { exec } = require('child_process');
const { PORT, HOST, FIXTURES } = process.env.NODE_ENV === "production" ? require('./config/env/production.js') : require('./config/env/development.js');
const setDependencies = require('./config/globals.js');
const { installFixtures } = require('./utils/index.js');
/**
* @function bootstrap
* @return {type} {bootstrap the connection and routes}
*/
const bootstrap = async () => {
require('./config/logger.js');
const routes = require('./config/routes.js');
const middlewares = require('./config/middlewares/index.js');
const connection = require('./config/connection.js');
let app = express();
let middlewaresResult = await middlewares(app);
//let connectionResult = await connection();
if (/*connectionResult.ok*/ true) {
if (middlewaresResult.ok) {
app.use(express.static('./client/public'));
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.set('views', path.resolve(__dirname, './views'));
let routesLoades = await routes(app);//define routes
//debugger;
if (routesLoades.ok) {
app.listen(PORT, () => console.log("App listen on: ", `${HOST}:${PORT}`))//lift the server
} else {
errorStarting(routesLoades.error);//log the error
}
} else {
errorStarting(middlewaresResult.error);//log the error
}
} else {
errorStarting(connectionResult.error);//log the error
}
}
const errorStarting = (error) => {
console.log('Unable to bootstrap the app ', error);
}
setDependencies()
.then(bootstrap)
.catch(errorStarting)