feat: initial commit
This commit is contained in:
1
.env.example
Normal file
1
.env.example
Normal file
@@ -0,0 +1 @@
|
||||
PROBE_PORT=3567
|
||||
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY probe-server.js /app/probe-server.js
|
||||
|
||||
ENV PORT=19090
|
||||
ENV HOST=0.0.0.0
|
||||
|
||||
EXPOSE 19090
|
||||
|
||||
CMD ["node", "probe-server.js"]
|
||||
|
||||
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
services:
|
||||
probe-server:
|
||||
build:
|
||||
context: .
|
||||
container_name: yc-probe-server
|
||||
restart: always
|
||||
environment:
|
||||
PORT: ${PROBE_PORT:-19090}
|
||||
HOST: 0.0.0.0
|
||||
ports:
|
||||
- "${PROBE_PORT:-19090}:${PROBE_PORT:-19090}"
|
||||
|
||||
26
probe-server.js
Normal file
26
probe-server.js
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
const net = require('node:net');
|
||||
|
||||
const PORT = Number(process.env.PORT || 19090);
|
||||
const HOST = process.env.HOST || '0.0.0.0';
|
||||
|
||||
if (Number.isNaN(PORT)) {
|
||||
throw new Error('PORT must be a number');
|
||||
}
|
||||
|
||||
const server = net.createServer((socket) => {
|
||||
socket.setKeepAlive(true, 15000);
|
||||
|
||||
socket.on('data', (buf) => {
|
||||
const msg = buf.toString('utf8').trim();
|
||||
if (msg === 'ping') {
|
||||
socket.write('pong\n');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(PORT, HOST, () => {
|
||||
console.log(`[probe] listening on ${HOST}:${PORT}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user