// src/server.mjs import { createServer } from 'node:http'; export function createAppServer() { return createServer((request, response) => { // The deployed runtime's abort signal: end the response when it fires. request.signal?.addEventListener('abort', () => response.destroy(), { once: true }); const send = (status, type, body) => { if (response.destroyed) return; response.writeHead(status, { 'content-type': type }); response.end(body); }; // A target that does not parse as a URL names no route, so it is answered 404 below. let pathname = null; try { pathname = new URL(request.url, 'http://localhost').pathname; } catch {} if (request.method === 'GET' && pathname === '/health') return send(200, 'application/json', JSON.stringify({ ok: true })); if (request.method === 'GET' && pathname === '/api/hello') return send(200, 'text/plain; charset=utf-8', 'hello world'); send(404, 'application/json', JSON.stringify({ error: 'not_found' })); }); }