refactor: migrate from node:http to Express with Express.js tests
All checks were successful
/ checks (push) Successful in 9s
/ deploy (push) Successful in 7s

This commit is contained in:
Noah Holt 2026-08-10 23:03:21 -05:00
parent 6dd9c6e6ee
commit 1365bd7644
6 changed files with 2391 additions and 38 deletions

View file

@ -1,32 +1,23 @@
import { createServer } from "node:http";
import express from "express";
import { hostname } from "node:os";
import { greeting } from "./greeting.js";
const app = express();
const port = Number(process.env.PORT ?? 3000);
const sha = process.env.GIT_SHA ?? "dev";
const server = createServer((req, res) => {
if (req.url === "/healthz") {
res.writeHead(200, { "content-type": "text/plain" });
res.end("ok");
return;
}
res.writeHead(200, { "content-type": "application/json" });
res.end(
JSON.stringify(
{
service: "demo-app",
message: greeting(),
sha,
pod: hostname(),
time: new Date().toISOString(),
},
null,
2,
) + "\n",
);
app.get("/healthz", (_req, res) => {
res.type("text/plain").send("ok");
});
server.listen(port, () => {
console.log(`demo-app ${sha} listening on :${port}`);
app.get("/", (_req, res) => {
res.json({
service: "demo-app",
message: greeting(),
sha,
pod: hostname(),
time: new Date().toISOString(),
});
});
export { app, port };