-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.js
More file actions
executable file
·87 lines (76 loc) · 2.51 KB
/
entity.js
File metadata and controls
executable file
·87 lines (76 loc) · 2.51 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var fs = require('fs');
var express = require('express');
var indRoutes = require('./src/routes/individualRoutes').indRoutes;
var familyRoutes = require('./src/routes/familyRoutes').familyRoutes;
var importRoutes = require('./src/routes/importRoutes').importRoutes;
var queryRoutes = require('./src/routes/queryRoutes').queryRoutes;
var createConnection = require('./src/controllers/dbConn.js').createConnection;
const configData = require('./src/config/config.js');
const { app : {expressPort} } = configData;
var initialize = require('./src/controllers/entityController.js').initialize;
console.log("Variable to resolve the path");
console.log("file path is "+__filename);
console.log("Dir Path is "+__dirname);
// import/ES6 not supported by Nodejs
/*
import {
initialize
} from './src/controllers/entityController.js';
*/
const app = express();
// EXPRESS_PORT will be provided from environment file for docker setup
//const EXPRESS_PORT = 8081;
app.use(express.json());
// Specific endpoint in the route gets called based on the URL.
// Pass express app to Individual Routes
try {
indRoutes(app);
familyRoutes(app);
importRoutes(app);
queryRoutes(app);
} catch(err) {
console.log("Error in routes "+err);
}
var server = app.listen(expressPort, async () => {
var host = server.address().address;
var port = server.address().port;
//server.setTimeout();
try {
await createConnection();
console.log("Creating Main Client Connection");
//console.log(client);
// Initializing database Collections
console.log("Calling initialize to create initial collections ");
var data = await initialize();
} catch (e) {
console.log("Error is "+e);
}
console.log(`Individual Express app listening http://${host}:${port}`);
});
// Handle server errors
server.on('error', (error) => {
if (error.syscall !== 'listen') {
throw error;
}
port = expressPort;
const bind = typeof port === 'string'
? `Port ${port}`
: `Port ${port}`;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.log(`${bind} requires elevated privileges`);
process.exit(1);
break;
case 'EADDRINUSE':
console.log(`${bind} is already in use`);
process.exit(1);
break;
default:
console.log(error);
// throw error;
}
});
app.get('/', (req, res) =>
res.send('Node and express server is running on port '+expressPort)
);