Initial commit
This commit is contained in:
commit
5d4f3c0965
11 changed files with 194 additions and 0 deletions
3
src/greeting.ts
Normal file
3
src/greeting.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export function greeting(): string {
|
||||
return "Hello from the homelab pipeline!";
|
||||
}
|
||||
7
src/index.test.ts
Normal file
7
src/index.test.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { greeting } from "./greeting.js";
|
||||
|
||||
test("greeting mentions the homelab", () => {
|
||||
assert.match(greeting(), /homelab/);
|
||||
});
|
||||
32
src/index.ts
Normal file
32
src/index.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { createServer } from "node:http";
|
||||
import { hostname } from "node:os";
|
||||
import { greeting } from "./greeting.js";
|
||||
|
||||
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",
|
||||
);
|
||||
});
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(`demo-app ${sha} listening on :${port}`);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue