diff --git a/src/server/index.ts b/src/server/index.ts index c905249..d93fb21 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -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( @@ -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(