Skip to content

Commit

Permalink
Changed routing table to allow assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Mqxx committed Oct 17, 2024
1 parent 9e172b6 commit 1643feb
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { route, type Route } from "@std/http/unstable-route";
import { serveFile } from "@std/http/file-server";
import { serveDir, serveFile } from "@std/http/file-server";

const routes: Route[] = [
{
Expand All @@ -10,12 +10,22 @@ const routes: Route[] = [
)
},
{
pattern: new URLPattern({ pathname: '/:page' }),
pattern: new URLPattern({ pathname: '/:page([^\/]+\/?)' }),
handler: (request, _info, parameters) => serveFile(
request,
`./dist/route/${parameters?.pathname.groups.page}/index.html`
)
},
{
pattern: new URLPattern({ pathname: '/:page/:asset*' }),
handler: (request, _info, parameters) => {
const groups = parameters?.pathname.groups;
return serveFile(
request,
`./dist/route/${groups?.page}/${groups?.asset}`
)
}
},
{
pattern: new URLPattern({ pathname: '/' }),
handler: (request) => serveFile(
Expand All @@ -29,4 +39,7 @@ function defaultHandler(_req: Request) : Response {
return new Response("Not found", { status: 404 });
}

Deno.serve(route(routes, defaultHandler));
Deno.serve(
{port: 8080},
route(routes, defaultHandler)
);

0 comments on commit 1643feb

Please sign in to comment.