my-app/server.js
Shautvast 521d86e50d Add Hello World test application for Hostityourself
Includes a Node.js HTTP server, static HTML page, and Dockerfile
for containerized self-hosting. Exposes a /health endpoint for
platform health checks.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-19 09:50:54 +01:00

30 lines
838 B
JavaScript

const http = require('http');
const fs = require('fs');
const path = require('path');
const PORT = process.env.PORT || 3000;
const server = http.createServer((req, res) => {
if (req.url === '/' || req.url === '/index.html') {
const filePath = path.join(__dirname, 'index.html');
fs.readFile(filePath, (err, data) => {
if (err) {
res.writeHead(500);
res.end('Error loading page');
return;
}
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data);
});
} else if (req.url === '/health') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ status: 'ok' }));
} else {
res.writeHead(404);
res.end('Not found');
}
});
server.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});