demo-app/src/index.ts

33 lines
792 B
TypeScript

import express from "express";
import { hostname } from "node:os";
import { greeting } from "./greeting.js";
import { getUtcTimestamp } from "./services/database.js";
const app = express();
const port = Number(process.env.PORT ?? 3000);
const sha = process.env.GIT_SHA ?? "dev";
app.get("/healthz", (_req, res) => {
res.type("text/plain").send("ok");
});
app.get("/", (_req, res) => {
res.json({
service: "demo-app",
message: greeting(),
sha,
pod: hostname(),
time: new Date().toISOString(),
});
});
app.get("/utc-time", async (_req, res) => {
const utcTime = await getUtcTimestamp();
if (!utcTime) {
res.status(503).json({ error: "Database not configured or unavailable" });
return;
}
res.json({ utc_time: utcTime });
});
export { app, port };