Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

templates(cloudflare-workers): convert main entry file from JS → TS #9774

Merged
merged 4 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion templates/cloudflare-workers/load-context.ts
Original file line number Diff line number Diff line change
@@ -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<PlatformProxy<Env>, "dispose" | "caches"> & {
caches: CacheStorage;
};

declare module "@remix-run/cloudflare" {
interface AppLoadContext {
cloudflare: Omit<PlatformProxy<Env>, "dispose">;
cloudflare: Cloudflare;
}
}
2 changes: 1 addition & 1 deletion templates/cloudflare-workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -50,4 +53,4 @@ export default {
return new Response("An unexpected error occurred", { status: 500 });
}
},
};
} satisfies ExportedHandler<Env & { __STATIC_CONTENT: KVNamespace<string> }>;
2 changes: 1 addition & 1 deletion templates/cloudflare-workers/wrangler.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down