diff --git a/templates/cloudflare-workers/load-context.ts b/templates/cloudflare-workers/load-context.ts index e9604b71ba0..5fc575ba11c 100644 --- a/templates/cloudflare-workers/load-context.ts +++ b/templates/cloudflare-workers/load-context.ts @@ -1,7 +1,13 @@ import { type PlatformProxy } from "wrangler"; +// PlatformProxy’s caches property is incompatible with the caches global +// https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/api/integrations/platform/caches.ts +type Cloudflare = Omit, "dispose" | "caches"> & { + caches: CacheStorage; +}; + declare module "@remix-run/cloudflare" { interface AppLoadContext { - cloudflare: Omit, "dispose">; + cloudflare: Cloudflare; } } diff --git a/templates/cloudflare-workers/package.json b/templates/cloudflare-workers/package.json index 94c82f16be8..5c226bfde73 100644 --- a/templates/cloudflare-workers/package.json +++ b/templates/cloudflare-workers/package.json @@ -7,7 +7,7 @@ "deploy": "wrangler deploy", "dev": "remix vite:dev", "lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .", - "start": "wrangler dev ./server.js", + "start": "wrangler dev", "typegen": "wrangler types", "typecheck": "tsc" }, diff --git a/templates/cloudflare-workers/server.js b/templates/cloudflare-workers/server.ts similarity index 75% rename from templates/cloudflare-workers/server.js rename to templates/cloudflare-workers/server.ts index 034653d326a..7a988c47d9b 100644 --- a/templates/cloudflare-workers/server.js +++ b/templates/cloudflare-workers/server.ts @@ -1,11 +1,14 @@ import { getAssetFromKV } from "@cloudflare/kv-asset-handler"; -import { createRequestHandler } from "@remix-run/cloudflare"; -import * as remixBuild from "./build/server"; +import { createRequestHandler, type ServerBuild } from "@remix-run/cloudflare"; +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore This file won’t exist if it hasn’t yet been built +import * as build from "./build/server"; // eslint-disable-line import/no-unresolved // eslint-disable-next-line import/no-unresolved import __STATIC_CONTENT_MANIFEST from "__STATIC_CONTENT_MANIFEST"; const MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST); -const handleRemixRequest = createRequestHandler(remixBuild); +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const handleRemixRequest = createRequestHandler(build as any as ServerBuild); export default { async fetch(request, env, ctx) { @@ -50,4 +53,4 @@ export default { return new Response("An unexpected error occurred", { status: 500 }); } }, -}; +} satisfies ExportedHandler }>; diff --git a/templates/cloudflare-workers/wrangler.toml b/templates/cloudflare-workers/wrangler.toml index 51b671d52f8..bdebe9f88ea 100644 --- a/templates/cloudflare-workers/wrangler.toml +++ b/templates/cloudflare-workers/wrangler.toml @@ -1,6 +1,6 @@ name = "remix-cloudflare-workers-template" -main = "./server.js" +main = "./server.ts" workers_dev = true # https://developers.cloudflare.com/workers/platform/compatibility-dates compatibility_date = "2023-04-20"