forked from cloudflare/cloudflare-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy to Cloudflare Workers too (cloudflare#16874)
* Deploy with Workers Assets too * Update to only production * Add preview too --------- Co-authored-by: kodster28 <[email protected]>
- Loading branch information
1 parent
e9582cc
commit f5d70c5
Showing
10 changed files
with
91 additions
and
5 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
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 |
---|---|---|
|
@@ -24,4 +24,5 @@ pnpm-debug.log* | |
/playwright/.cache/ | ||
|
||
.wrangler | ||
/assets/secrets | ||
/assets/secrets | ||
/worker/functions/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
_redirects |
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 |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
"~/*": ["src/*"] | ||
} | ||
}, | ||
"exclude": ["dist", "functions"] | ||
"exclude": ["dist", "functions", "./worker"] | ||
} |
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,11 @@ | ||
// Generated by Wrangler on Tue Sep 17 2024 00:57:27 GMT-0400 (Eastern Daylight Time) | ||
// by running `wrangler types -c wrangler-workers.toml --experimental-include-runtime` | ||
|
||
interface Env { | ||
API_DOCS_KV: KVNamespace; | ||
ASSETS: Fetcher; | ||
} | ||
declare module "*/_redirects" { | ||
const value: string; | ||
export default value; | ||
} |
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,17 @@ | ||
import { WorkerEntrypoint } from "cloudflare:workers"; | ||
import { generateRedirectsEvaluator } from "redirects-in-workers"; | ||
import redirectsFileContents from "../dist/_redirects"; | ||
import functions from "./functions"; | ||
|
||
const redirectsEvaluator = generateRedirectsEvaluator(redirectsFileContents); | ||
|
||
export default class extends WorkerEntrypoint<Env> { | ||
override async fetch(request: Request) { | ||
const redirect = await redirectsEvaluator(request, this.env.ASSETS); | ||
if (redirect) { | ||
return redirect; | ||
} | ||
|
||
return await functions.fetch(request, this.env, this.ctx); | ||
} | ||
} |
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,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"target": "ESNext", | ||
"allowJs": true, | ||
"resolveJsonModule": true, | ||
"moduleDetection": "force", | ||
"isolatedModules": true, | ||
"verbatimModuleSyntax": true, | ||
"strict": true, | ||
"noUncheckedIndexedAccess": true, | ||
"noImplicitOverride": true, | ||
"module": "Preserve", | ||
"noEmit": true, | ||
"lib": ["ESNext"], | ||
"types": ["../.wrangler/types/runtime.d.ts", "../worker-configuration.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name = "cloudflare-docs" | ||
account_id = "b54f07a6c269ecca2fa60f1ae4920c99" | ||
compatibility_date = "2022-09-27" | ||
main = "./worker/index.ts" | ||
|
||
rules = [ | ||
{ type = "Text", globs = ["**/_redirects"], fallthrough = true }, | ||
] | ||
|
||
[experimental_assets] | ||
directory = "./dist" | ||
binding = "ASSETS" | ||
not_found_handling = "404-page" | ||
|
||
[[kv_namespaces]] | ||
binding = "API_DOCS_KV" | ||
id = "77919060ee0444caa5113f5866b047df" |