forked from reaverlee/influxdb_auto_insert_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (31 loc) · 941 Bytes
/
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
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const axios = require("axios");
const routes = require("./api/routes/index");
const app = express();
app.use(cors());
app.use(morgan("combined"));
app.use(express.json());
app.use(routes);
app.get("/ping", function (req, res) {
res.status(200).json({ message: "pong" });
});
const checkInfluxDBHealth = async () => {
try {
const response = await axios.get(`${process.env.INFLUX_HOST_URL}/health`);
if (response.status === 204) {
console.log("InfluxDB is healthy");
} else {
console.log("InfluxDB health status:", response.status);
}
} catch (error) {
console.error("Error checking InfluxDB health:", error);
}
};
const PORT = process.env.PORT;
app.listen(PORT, async () => {
await checkInfluxDBHealth();
console.log(`Listening to request on port: ${PORT}`);
});