-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'workers-assets-classic-compiler'
- Loading branch information
Showing
16 changed files
with
250 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -713,3 +713,4 @@ | |
- zayenz | ||
- zhe | ||
- zwhitchcox | ||
- zwily |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ node_modules | |
/build | ||
/public/build | ||
.env | ||
.dev.vars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
templates/classic-remix-compiler/cloudflare-workers/app/tailwind.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
html, | ||
body { | ||
@apply bg-white dark:bg-gray-950; | ||
|
||
@media (prefers-color-scheme: dark) { | ||
color-scheme: dark; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
templates/classic-remix-compiler/cloudflare-workers/load-context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { type PlatformProxy } from "wrangler"; | ||
|
||
type GetLoadContextArgs = { | ||
request: Request; | ||
context: { | ||
cloudflare: Omit< | ||
PlatformProxy<Env, IncomingRequestCfProperties>, | ||
"dispose" | "caches" | ||
> & { | ||
caches: | ||
| PlatformProxy<Env, IncomingRequestCfProperties>["caches"] | ||
| CacheStorage; | ||
}; | ||
}; | ||
}; | ||
|
||
declare module "@remix-run/cloudflare" { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
interface AppLoadContext extends ReturnType<typeof getLoadContext> { | ||
// This will merge the result of `getLoadContext` into the `AppLoadContext` | ||
} | ||
} | ||
|
||
export function getLoadContext({ context }: GetLoadContextArgs) { | ||
return context; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+78.4 KB
templates/classic-remix-compiler/cloudflare-workers/public/logo-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.77 KB
templates/classic-remix-compiler/cloudflare-workers/public/logo-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
templates/classic-remix-compiler/cloudflare-workers/remix.env.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
/// <reference types="@remix-run/dev" /> | ||
/// <reference types="@remix-run/cloudflare" /> | ||
/// <reference types="@cloudflare/workers-types" /> | ||
|
||
declare module "__STATIC_CONTENT_MANIFEST" { | ||
const manifest: string; | ||
export default manifest; | ||
} |
58 changes: 20 additions & 38 deletions
58
templates/classic-remix-compiler/cloudflare-workers/server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,38 @@ | ||
import { getAssetFromKV } from "@cloudflare/kv-asset-handler"; | ||
import type { AppLoadContext } from "@remix-run/cloudflare"; | ||
import { createRequestHandler, logDevReady } from "@remix-run/cloudflare"; | ||
import * as build from "@remix-run/dev/server-build"; | ||
// eslint-disable-next-line import/no-unresolved | ||
import __STATIC_CONTENT_MANIFEST from "__STATIC_CONTENT_MANIFEST"; | ||
import { getLoadContext } from "./load-context"; | ||
|
||
const MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST); | ||
const handleRemixRequest = createRequestHandler(build, process.env.NODE_ENV); | ||
|
||
if (process.env.NODE_ENV === "development") { | ||
logDevReady(build); | ||
} | ||
|
||
export default { | ||
async fetch( | ||
request: Request, | ||
env: { | ||
__STATIC_CONTENT: Fetcher; | ||
}, | ||
ctx: ExecutionContext | ||
): Promise<Response> { | ||
async fetch(request, env, ctx): Promise<Response> { | ||
try { | ||
const url = new URL(request.url); | ||
const ttl = url.pathname.startsWith("/build/") | ||
? 60 * 60 * 24 * 365 // 1 year | ||
: 60 * 5; // 5 minutes | ||
return await getAssetFromKV( | ||
{ | ||
request, | ||
waitUntil: ctx.waitUntil.bind(ctx), | ||
} as FetchEvent, | ||
{ | ||
ASSET_NAMESPACE: env.__STATIC_CONTENT, | ||
ASSET_MANIFEST: MANIFEST, | ||
cacheControl: { | ||
browserTTL: ttl, | ||
edgeTTL: ttl, | ||
const loadContext = getLoadContext({ | ||
request, | ||
context: { | ||
cloudflare: { | ||
// This object matches the return value from Wrangler's | ||
// `getPlatformProxy` used during development via Remix's | ||
// `cloudflareDevProxyVitePlugin`: | ||
// https://developers.cloudflare.com/workers/wrangler/api/#getplatformproxy | ||
cf: request.cf, | ||
ctx: { | ||
waitUntil: ctx.waitUntil.bind(ctx), | ||
passThroughOnException: ctx.passThroughOnException.bind(ctx), | ||
}, | ||
caches, | ||
env, | ||
}, | ||
} | ||
); | ||
} catch (error) { | ||
// No-op | ||
} | ||
|
||
try { | ||
const loadContext: AppLoadContext = { | ||
env, | ||
}; | ||
}, | ||
}); | ||
return await handleRemixRequest(request, loadContext); | ||
} catch (error) { | ||
console.log(error); | ||
return new Response("An unexpected error occurred", { status: 500 }); | ||
} | ||
}, | ||
}; | ||
} satisfies ExportedHandler<Env>; |
Oops, something went wrong.