Skip to content

Commit

Permalink
Update index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Mqxx committed Nov 5, 2024
1 parent e73fc5a commit 418b611
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { route, type Route } from "@std/http/unstable-route";
import { serveFile } from "@std/http";
import { STATUS_CODE } from "@std/http";
import pageHandler from './request_handler/page_handler.ts';

const rootDirectory = './dist/';
const appDirectory = `${rootDirectory}/app/`;

const routes: Route[] = [
{
pattern: new URLPattern({ pathname: '/' }),
handler: (request) => {
return Response.redirect(
request.url + 'home',
STATUS_CODE.MovedPermanently
)
}
},
{
pattern: new URLPattern({ pathname: "/-/:staticAsset*" }),
handler: (request, _info, parameters) => pageHandler(
Expand All @@ -16,25 +25,26 @@ const routes: Route[] = [
)
},
{
pattern: new URLPattern({ pathname: '/:path*' }),
pattern: new URLPattern({ pathname: '/:path*/assets/:dynamicAsset*' }),
handler: (request, _info, parameters) => {
console.log(parameters?.pathname.groups.path)
return serveFile(request, appDirectory+'index.html')
}
},
{
pattern: new URLPattern({ pathname: '/:page/:dynamicAsset*' }),
handler: (request, _info, parameters) => {
const {page, dynamicAsset} = parameters?.pathname.groups ?? {};

const {path, dynamicAsset} = parameters?.pathname.groups ?? {};
return pageHandler(
request,
appDirectory,
page,
dynamicAsset
path,
'/assets/' + dynamicAsset
);
}
}
},
// {
// pattern: new URLPattern({ pathname: '/:path([^\.]+$)' }),
// handler: (request, _info, parameters) => {
// const {path} = parameters?.pathname.groups ?? {};
// console.log('page', path)
// return pageHandler(request, appDirectory, '')
// }
// },

];

Deno.serve(
Expand Down

0 comments on commit 418b611

Please sign in to comment.