-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(templates): integrate v2_dev (#6650)
Co-authored-by: Jacob Ebey <jacob.ebey@live.com>
- Loading branch information
1 parent
3b7d73b
commit 288c97c
Showing
34 changed files
with
207 additions
and
89 deletions.
There are no files selected for viewing
File renamed without changes.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// This should eventually be a npm package, but for now it lives here. | ||
// It's job is to notify the remix dev server of the version of the running | ||
// app to trigger HMR / HDR. | ||
|
||
import * as fs from "node:fs"; | ||
import * as path from "node:path"; | ||
import { logDevReady } from "@remix-run/node"; | ||
|
||
const buildPath = "server/index.mjs"; | ||
|
||
let lastTimeout; | ||
|
||
export default { | ||
sandbox: { | ||
async watcher() { | ||
if (lastTimeout) { | ||
clearTimeout(lastTimeout); | ||
} | ||
|
||
lastTimeout = setTimeout(async () => { | ||
const contents = fs.readFileSync( | ||
path.resolve(process.cwd(), buildPath), | ||
"utf8" | ||
); | ||
const manifestMatches = contents.matchAll(/manifest-([A-f0-9]+)\.js/g); | ||
const sent = new Set(); | ||
for (const match of manifestMatches) { | ||
const buildHash = match[1]; | ||
if (!sent.has(buildHash)) { | ||
sent.add(buildHash); | ||
logDevReady({ assets: { version: buildHash } }); | ||
} | ||
} | ||
}, 300); | ||
}, | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@aws | ||
runtime nodejs14.x | ||
runtime nodejs16.x | ||
# memory 1152 | ||
# timeout 30 | ||
# concurrency 1 |
File renamed without changes.
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,3 +1,4 @@ | ||
.DS_Store | ||
node_modules | ||
|
||
/.cache | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/favicon.ico | ||
Cache-Control: public, max-age=3600, s-maxage=3600 | ||
/build/* | ||
Cache-Control: public, max-age=31536000, immutable |
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,5 +1,5 @@ | ||
{ | ||
"version": 1, | ||
"include": ["/*"], | ||
"exclude": ["/build/*"] | ||
"exclude": ["/favicon.ico", "/build/*"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import { logDevReady } from "@remix-run/cloudflare"; | ||
import { createPagesFunctionHandler } from "@remix-run/cloudflare-pages"; | ||
import * as build from "@remix-run/dev/server-build"; | ||
|
||
if (process.env.NODE_ENV === "development") { | ||
logDevReady(build); | ||
} | ||
|
||
export const onRequest = createPagesFunctionHandler({ | ||
build, | ||
getLoadContext: (context) => context.env, | ||
getLoadContext: (context) => ({ env: context.env }), | ||
mode: process.env.NODE_ENV, | ||
}); |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,3 +1,4 @@ | ||
.DS_Store | ||
node_modules | ||
|
||
/.cache | ||
|
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
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,3 +1,8 @@ | ||
/// <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; | ||
} |
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,7 +1,53 @@ | ||
import { createEventHandler } from "@remix-run/cloudflare-workers"; | ||
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"; | ||
import __STATIC_CONTENT_MANIFEST from "__STATIC_CONTENT_MANIFEST"; | ||
|
||
addEventListener( | ||
"fetch", | ||
createEventHandler({ build, mode: process.env.NODE_ENV }) | ||
); | ||
const MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST); | ||
const handleRemixRequest = createRequestHandler(build, process.env.NODE_ENV); | ||
|
||
if (build.dev) { | ||
logDevReady(build); | ||
} | ||
|
||
export default { | ||
async fetch( | ||
request: Request, | ||
env: { | ||
__STATIC_CONTENT: Fetcher; | ||
}, | ||
ctx: ExecutionContext | ||
): 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, | ||
}, | ||
} | ||
); | ||
} catch (error) {} | ||
|
||
try { | ||
const loadContext: AppLoadContext = { | ||
env, | ||
}; | ||
return await handleRemixRequest(request, loadContext); | ||
} catch (error) { | ||
console.log(error); | ||
return new Response("An unexpected error occurred", { status: 500 }); | ||
} | ||
}, | ||
}; |
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
File renamed without changes.
Oops, something went wrong.