-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
53 lines (45 loc) · 1.2 KB
/
app.js
File metadata and controls
53 lines (45 loc) · 1.2 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
const express = require("express");
const config = require("./Config");
const logger = require("./Components/logger");
const mysql = require("./Components/mysql");
const elasticsearch = require("./Components/elasticsearch");
const app = express();
require("./Config/express")(app);
const startServer = async function(){
// Setup server
try{
const elasticsearchConnected = await elasticsearch.testConnection();
if(elasticsearchConnected){
logger.info("Elasticsearch connected!");
}
else{
logger.info("Failed to connect to Elasticsearch.");
}
}
catch(error) {
logger.error(error);
}
try{
const mysqlConnected = await mysql.query("select 1 as c1");
if(mysqlConnected[0].c1){
logger.info("Relational DB connected!");
}
else{
logger.info("Failed to connect to Relational Database.");
}
}
catch(error) {
logger.error(error);
}
// Start server
app.listen(config.port, function () {
logger.info("Server listening on %d, in %s mode", config.port, config.env);
});
};
startServer();
// when shutdown signal is received, do graceful shutdown
process.on("SIGINT", function () {
logger.info("Gracefully shutting down :)");
mysql.close();
process.exit();
});