-
Notifications
You must be signed in to change notification settings - Fork 472
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
feat: add cloudflare-pages preset #210
Merged
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5095270
feat: add cloudflare-pages preset
DaniFoldi 6e6c904
chore: add missing newline
DaniFoldi a8be954
chore(deps): update all non-major dependencies (#211)
renovate[bot] daa2038
fix: add missing include path `../../**/*` in generated tsconfig.jsonβ¦
didavid61202 234fffd
refactor: Use regular function style
DaniFoldi 59f47c0
fix: Reorganize structure
DaniFoldi 5a1fb54
fix: use correct main
DaniFoldi 55c4036
fix: Use .js extension for functions
DaniFoldi 00fadab
fix: use direct upload from wrangler
DaniFoldi 18adce2
fix: Use esm
DaniFoldi 24eb10a
fix: Call next function for assets
DaniFoldi 26b77a0
fix: wrangler pages dev also requires static folder
DaniFoldi 179b87f
Merge branch 'main' into DaniFoldi/main
danielroe 29faa36
fix: pages internally caches assets as needed
DaniFoldi 8edc5e1
fix: try to use rollup's entrypoint name config
DaniFoldi 0343554
fix: rename file after rollup output is compiled
DaniFoldi f3ae71d
feat: auto-detect `cloudflare_pages` preset
DaniFoldi 3e4a548
docs: Add docs for cloudflare pages preset
DaniFoldi 5c4a88c
Merge branch 'main' into pr/DaniFoldi/210
pi0 19343ea
refactor: merge into cloudflare.ts
pi0 7bbf70c
add testing notice to merge
pi0 abe5fd5
add type for ctx and remove unused params as todo
pi0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,52 @@ | ||
import '#internal/nitro/virtual/polyfill' | ||
import { requestHasBody, useRequestBody } from '../utils' | ||
import { nitroApp } from '../app' | ||
|
||
export async function onRequest (context) { | ||
// Contents of context object | ||
const { | ||
request, // same as existing Worker API | ||
env, // same as existing Worker API | ||
// params, // if filename includes [id] or [[path]] | ||
// waitUntil, // same as ctx.waitUntil in existing Worker API | ||
next // used for middleware or to fetch assets | ||
// data, // arbitrary space for passing data between middlewares | ||
} = context | ||
|
||
try { | ||
// const asset = await env.ASSETS.fetch(request, { cacheControl: assetsCacheControl }) | ||
const asset = await next() | ||
if (asset.status !== 404) { | ||
return asset | ||
} | ||
} catch (_err) { | ||
// Ignore | ||
} | ||
|
||
const url = new URL(request.url) | ||
let body | ||
if (requestHasBody(request)) { | ||
body = await useRequestBody(request) | ||
} | ||
|
||
const r = await nitroApp.localCall({ | ||
env, | ||
context, | ||
url: url.pathname + url.search, | ||
host: url.hostname, | ||
protocol: url.protocol, | ||
headers: request.headers, | ||
method: request.method, | ||
redirect: request.redirect, | ||
body | ||
}) | ||
return new Response(r.body, { | ||
headers: normalizeOutgoingHeaders(r.headers), | ||
status: r.status, | ||
statusText: r.statusText | ||
}) | ||
} | ||
|
||
function normalizeOutgoingHeaders (headers: Record<string, string | string[] | undefined>) { | ||
return Object.entries(headers).map(([k, v]) => [k, Array.isArray(v) ? v.join(',') : v]) | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this currently has no effect (src). unenv only picks known keys from input (url, method, headers, host, protocol, body). But we should definitely add cf context in later changes.