diff --git a/example/reactSSR/handlers/github.handler.ts b/example/reactSSR/handlers/github.handler.ts index aee59eb0..092d62b7 100644 --- a/example/reactSSR/handlers/github.handler.ts +++ b/example/reactSSR/handlers/github.handler.ts @@ -1,24 +1,23 @@ import { Handler, RequestContext, file } from "../../../mod.ts"; -const base = `https://raw.githubusercontent.com/sejori/peko/main/example/reactSSR/`; - export const githubHandler = (path: string, type?: string): Handler => - async (ctx: RequestContext<{ env?: { ENVIRONMENT: string } }>) => - ( - await file( - ctx.state.env?.ENVIRONMENT === "production" - ? new URL(`${base}${path}`) - : new URL(".." + path, import.meta.url), - { - headers: new Headers({ - ...(type && { "Content-Type": type }), - // instruct browser to cache file in prod env - "Cache-Control": - ctx.state.env?.ENVIRONMENT === "production" - ? "max-age=86400, stale-while-revalidate=86400" - : "no-store", - }), - } - ) + async (ctx: RequestContext<{ env?: { ENVIRONMENT: string } }>) => { + const base = + ctx.state.env?.ENVIRONMENT === "production" || !import.meta.url + ? `https://raw.githubusercontent.com/sejori/peko/main/example/reactSSR/` + : import.meta.url.replace("handlers/github.handler.ts", ""); + + return ( + await file(new URL(`${base}${path}`), { + headers: new Headers({ + ...(type && { "Content-Type": type }), + // instruct browser to cache file in prod env + "Cache-Control": + ctx.state.env?.ENVIRONMENT === "production" + ? "max-age=86400, stale-while-revalidate=86400" + : "no-store", + }), + }) )(ctx); + }; diff --git a/tsconfig.json b/tsconfig.json index a6035787..0ba49af9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "module": "esnext", "lib": ["dom", "esnext"], "types": ["@cloudflare/workers-types"], - "jsx": "react", + "jsx": "react-jsx", "allowSyntheticDefaultImports": true } } diff --git a/wrangler.toml b/wrangler.toml index 18417f9a..a33dabdd 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -1,6 +1,5 @@ name = "peko" main = "scripts/wrangler/main.ts" -node_compat = true compatibility_date = "2024-02-23" [vars]