This repository has been archived on 2025-12-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
quizzy-application/drill-and-practice/middlewares/renderMiddleware.js
2023-03-13 12:48:02 +02:00

25 lines
499 B
JavaScript

import { configure, renderFile } from "../deps.js";
const renderMiddleware = async (context, next) => {
configure({
views: `${Deno.cwd()}/views/`,
});
context.render = async (file, data) => {
if (!data) {
data = {};
}
if (context.user) {
data.user = context.user;
}
context.response.headers.set("Content-Type", "text/html; charset=utf-8");
context.response.body = await renderFile(file, data);
};
await next();
};
export { renderMiddleware };