diff --git a/apps/worker/src/index.ts b/apps/worker/src/index.ts index 9440f78..247af87 100644 --- a/apps/worker/src/index.ts +++ b/apps/worker/src/index.ts @@ -111,4 +111,19 @@ app.route("/api/group", newapiGroupRoutes); app.route("/v1", proxyRoutes); +app.notFound((c) => { + const path = c.req.path; + if ( + path === "/api" || + path.startsWith("/api/") || + path === "/v1" || + path.startsWith("/v1/") + ) { + return c.json({ error: "Not Found" }, 404); + } + const assets = (c.env as { ASSETS?: { fetch: (input: Request) => Promise } }) + .ASSETS; + return assets ? assets.fetch(c.req.raw) : c.text("Not Found", 404); +}); + export default app; diff --git a/apps/worker/wrangler.toml b/apps/worker/wrangler.toml index 0e36c6b..de16418 100644 --- a/apps/worker/wrangler.toml +++ b/apps/worker/wrangler.toml @@ -14,5 +14,6 @@ database_id = "00000000-0000-0000-0000-000000000000" [assets] directory = "../admin/dist" +binding = "ASSETS" not_found_handling = "single-page-application" -run_worker_first = ["/api/*", "/v1/*"] +run_worker_first = true