feat: implement dashboard mockup and route
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { homeRoute } from "./routes/home";
|
||||
import { healthRoute } from "./routes/health";
|
||||
import { dashboardRoute } from "./routes/dashboard";
|
||||
import { file } from "bun";
|
||||
import { join, resolve } from "path";
|
||||
|
||||
@@ -19,12 +20,6 @@ export async function router(request: Request): Promise<Response> {
|
||||
const relativePath = url.pathname.replace(/^\/public/, "");
|
||||
|
||||
// Resolve full path
|
||||
// We use join with relativePath. If relativePath starts with /, join handles it correctly
|
||||
// effectively treating it as a segment.
|
||||
// However, to be extra safe with 'resolve', we ensure we are resolving from publicDir.
|
||||
// simple join(publicDir, relativePath) is usually enough with 'bun'.
|
||||
// But we use 'resolve' to handle .. segments correctly.
|
||||
// We prepend '.' to relativePath to ensure it's treated as relative to publicDir logic
|
||||
const normalizedRelative = relativePath.startsWith("/") ? "." + relativePath : relativePath;
|
||||
const requestedPath = resolve(publicDir, normalizedRelative);
|
||||
|
||||
@@ -35,8 +30,6 @@ export async function router(request: Request): Promise<Response> {
|
||||
return new Response(staticFile);
|
||||
}
|
||||
} else {
|
||||
// If path traversal detected, return 403 or 404.
|
||||
// 403 indicates we caught them.
|
||||
return new Response("Forbidden", { status: 403 });
|
||||
}
|
||||
}
|
||||
@@ -47,6 +40,9 @@ export async function router(request: Request): Promise<Response> {
|
||||
if (url.pathname === "/health") {
|
||||
return healthRoute();
|
||||
}
|
||||
if (url.pathname === "/dashboard") {
|
||||
return dashboardRoute();
|
||||
}
|
||||
}
|
||||
|
||||
return new Response("Not Found", { status: 404 });
|
||||
|
||||
Reference in New Issue
Block a user