Support compiling static assets, add compile task

This commit is contained in:
Râu Cao 2024-12-03 17:25:19 +01:00
parent cea96e170d
commit 2ac3180c0f
Signed by: raucao
GPG Key ID: 37036C356E56CC51
2 changed files with 4 additions and 2 deletions

View File

@ -1,7 +1,8 @@
{ {
"tasks": { "tasks": {
"dev": "deno run --allow-all --watch server.ts", "dev": "deno run --allow-all --watch server.ts",
"server": "deno run --allow-all server.ts" "server": "deno run --allow-all server.ts",
"compile": "deno compile --allow-all --include ./assets/ --output substr server.ts"
}, },
"imports": { "imports": {
"@deno/gfm": "jsr:@deno/gfm@^0.9.0", "@deno/gfm": "jsr:@deno/gfm@^0.9.0",

View File

@ -85,6 +85,7 @@ router.get("/:username/:identifier", async (ctx) => {
}); });
router.get("/assets/:path*", async (ctx) => { router.get("/assets/:path*", async (ctx) => {
console.log(import.meta.dirname);
try { try {
let filePath = ctx.params.path || ""; let filePath = ctx.params.path || "";
let root: string; let root: string;
@ -93,7 +94,7 @@ router.get("/assets/:path*", async (ctx) => {
filePath = filePath.replace(/^g\//, ""); filePath = filePath.replace(/^g\//, "");
root = "/tmp/substr"; root = "/tmp/substr";
} else { } else {
root = `${Deno.cwd()}/assets`; root = `${import.meta.dirname}/assets`;
} }
await send(ctx, filePath, { root }); await send(ctx, filePath, { root });