Add basic template rendering route
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user