-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
31 lines (27 loc) · 829 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
const express = require('express');
const os = require('os');
const app = express();
const port = process.env.PORT || 3000;
// Function to get the local IP address
function getLocalIpAddress() {
const interfaces = os.networkInterfaces();
for (const name of Object.keys(interfaces)) {
for (const iface of interfaces[name]) {
if (iface.family === 'IPv4' && !iface.internal) {
return iface.address;
}
}
}
return 'IP address not found';
}
app.get('/', (req, res) => {
const ipAddress = getLocalIpAddress();
res.send(`Hello from Simple Web App HA! This app is running on IP address: ${ipAddress}`);
});
// Add a health check endpoint
app.get('/health', (req, res) => {
res.status(200).send('OK');
});
app.listen(port, () => {
console.log(`App running on http://localhost:${port}`);
});