First commit

This commit is contained in:
AndrewTrieu
2023-03-09 11:21:18 +02:00
commit be427eda10
27 changed files with 262 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
const errorMiddleware = async (context, next) => {
try {
await next();
} catch (e) {
console.log(e);
}
};
export { errorMiddleware };

View File

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

View File

@@ -0,0 +1,15 @@
import { send } from "../deps.js";
const serveStaticMiddleware = async (context, next) => {
if (context.request.url.pathname.startsWith("/static")) {
const path = context.request.url.pathname.substring(7);
await send(context, path, {
root: `${Deno.cwd()}/static`,
});
} else {
await next();
}
};
export { serveStaticMiddleware };