Create a "hanger" server

This commit is contained in:
2024-07-24 16:40:40 +02:00
commit c864d2e625
2 changed files with 30 additions and 0 deletions

7
Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
FROM node:lts-alpine
USER node
WORKDIR /app
ENV NODE_ENV production
COPY --chown=node:node index.mjs ./
EXPOSE 3000
CMD ["node", "./index.mjs"]

23
index.mjs Normal file
View File

@@ -0,0 +1,23 @@
import { createServer } from 'node:http';
import { clearInterval, setInterval } from 'node:timers';
const server = createServer((req, res) => {
console.log(
`Caught ${req.headers['x-forwarded-for']} on ${req.method} ${req.url}`
);
let msg = ':) you are an idiot hahahahaha :)';
let charIdx = 0;
let intervalId = setInterval(() => {
if (charIdx === msg.length) {
charIdx = 0;
res.write('\n');
} else {
res.write(msg[charIdx++]);
}
}, 3000);
res.once('close', () => clearInterval(intervalId));
});
server.listen(3000);