Skip to content

Commit

Permalink
Restore TS cloudflare worker’s entry file + name
Browse files Browse the repository at this point in the history
reproduces the changes suggested in remix-run/remix#9774
  • Loading branch information
acusti committed Jul 22, 2024
1 parent a209b26 commit 0f9bcab
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 18 deletions.
9 changes: 8 additions & 1 deletion apps/site/load-context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { type PlatformProxy } from "wrangler";

// NOTE: 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
// TS error: Property 'default' is missing in type 'CacheStorage' but required in type 'CacheStorage_2'.
type Cloudflare = Omit<PlatformProxy<Env>, "dispose" | "caches"> & {
caches: CacheStorage;
};

declare module "@remix-run/cloudflare" {
interface AppLoadContext {
cloudflare: Omit<PlatformProxy<Env>, "dispose">;
cloudflare: Cloudflare;
}
}
11 changes: 7 additions & 4 deletions apps/site/server.js → apps/site/worker.ts
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 apps/site/wrangler.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "superflare-site",
"main": "./server.js",
"main": "./worker.ts",
"workers_dev": true,
"compatibility_date": "2023-04-20",
"site": {
Expand Down
9 changes: 8 additions & 1 deletion examples/remix-cms/load-context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { type PlatformProxy } from "wrangler";

// NOTE: 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
// TS error: Property 'default' is missing in type 'CacheStorage' but required in type 'CacheStorage_2'.
type Cloudflare = Omit<PlatformProxy<Env>, "dispose" | "caches"> & {
caches: CacheStorage;
};

declare module "@remix-run/cloudflare" {
interface AppLoadContext {
cloudflare: Omit<PlatformProxy<Env>, "dispose">;
cloudflare: Cloudflare;
}
}
11 changes: 7 additions & 4 deletions examples/remix-cms/server.js → examples/remix-cms/worker.ts
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 examples/remix-cms/wrangler.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "remix-cms",
"compatibility_flags": ["nodejs_compat"],
"main": "./server.js",
"main": "./worker.ts",
"workers_dev": true,
"compatibility_date": "2023-04-20",
"site": {
Expand Down
9 changes: 8 additions & 1 deletion templates/remix/load-context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { type PlatformProxy } from "wrangler";

// NOTE: 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
// TS error: Property 'default' is missing in type 'CacheStorage' but required in type 'CacheStorage_2'.
type Cloudflare = Omit<PlatformProxy<Env>, "dispose" | "caches"> & {
caches: CacheStorage;
};

declare module "@remix-run/cloudflare" {
interface AppLoadContext {
cloudflare: Omit<PlatformProxy<Env>, "dispose">;
cloudflare: Cloudflare;
}
}
11 changes: 7 additions & 4 deletions templates/remix/server.js → templates/remix/worker.ts
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/remix/wrangler.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "remix-cms",
"compatibility_flags": ["nodejs_compat"],
"main": "./server.js",
"main": "./worker.ts",
"workers_dev": true,
"compatibility_date": "2023-04-20",
"site": {
Expand Down

0 comments on commit 0f9bcab

Please sign in to comment.