Add basic template rendering route

This commit is contained in:
2026-01-01 21:12:38 -06:00
parent 539717efda
commit 03980e114b
3 changed files with 44 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
/// <reference lib="dom" />
import nunjucks from "nunjucks";
import { DateTime } from "ts-luxon";
import { contentTypes } from "./content-types";
import { multiHandler } from "./handlers";
import { HttpCode, httpCodes } from "./http-codes";
@@ -72,6 +74,29 @@ const routes: Route[] = [
};
},
},
{
path: "/time",
methods: ["GET"],
handler: async (_req): Promise<Result> => {
const now = DateTime.now();
const template = `
<html>
<head></head>
<body>
{{ now }}
</body>
</html>
`;
const result = nunjucks.renderString(template, { now });
return {
code: httpCodes.success.OK,
contentType: contentTypes.text.html,
result,
};
},
},
];
export { routes };