mirror of
https://github.com/cloudflare/cloudflare-docs.git
synced 2026-01-11 20:06:58 +00:00
Add _headers back and bump wrangler@4.1.0 (#20937)
* Bump wrangler@4.1.0 * Add _headers back * Remove double-slash evaluation in Worker * Add /api redirect
This commit is contained in:
parent
1c68765c12
commit
f5339d91b6
13 changed files with 267 additions and 908 deletions
2
.gitattributes
vendored
2
.gitattributes
vendored
|
|
@ -18,7 +18,7 @@
|
|||
*.xml text eol=lf
|
||||
*.yaml text eol=lf
|
||||
*.yml text eol=lf
|
||||
_redirects text eol=lf
|
||||
__redirects text eol=lf
|
||||
.editorconfig text eol=lf
|
||||
.gitattributes text eol=lf
|
||||
.prettierignore text eol=lf
|
||||
|
|
|
|||
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
|
|
@ -14,7 +14,7 @@
|
|||
*.js @cloudflare/developer-advocacy @kristianfreeman @kodster28 @pedrosousa @haleycode @maxvp @marciocloudflare @GregBrimble @KianNH @WalshyDev
|
||||
*.ts @cloudflare/developer-advocacy @kristianfreeman @kodster28 @pedrosousa @haleycode @maxvp @marciocloudflare @GregBrimble @KianNH @WalshyDev
|
||||
/src/content/workers-ai-models/ @craigsdennis @pedrosousa @cloudflare/pcx-technical-writing
|
||||
/public/_redirects @GregBrimble @KianNH @pedrosousa @WalshyDev @cloudflare/pcx-technical-writing
|
||||
/public/__redirects @GregBrimble @KianNH @pedrosousa @WalshyDev @cloudflare/pcx-technical-writing
|
||||
|
||||
# AI
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@ dist
|
|||
# generated actions JS
|
||||
.github/**/*/index.js
|
||||
.github/CODEOWNERS
|
||||
public/_redirects
|
||||
public/__redirects
|
||||
public/analytics/static/downloads/main.css
|
||||
src/content/workers-ai-models/*.json
|
||||
|
|
|
|||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
|
@ -3,5 +3,6 @@
|
|||
"editor.formatOnSave": true,
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"typescript.tsdk": "node_modules/typescript/lib",
|
||||
"cSpell.enableFiletypes": ["mdx"]
|
||||
"cSpell.enableFiletypes": ["mdx"],
|
||||
"files.associations": { "__redirects": "plaintext", "_headers": "plaintext" }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { readFile } from "fs/promises";
|
||||
|
||||
async function main() {
|
||||
const redirects = await readFile("public/_redirects", { encoding: "utf-8" });
|
||||
const redirects = await readFile("public/__redirects", { encoding: "utf-8" });
|
||||
|
||||
let numInfiniteRedirects = 0;
|
||||
let numUrlsWithFragment = 0;
|
||||
|
|
|
|||
1133
package-lock.json
generated
1133
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -121,7 +121,7 @@
|
|||
"unist-util-visit": "5.0.0",
|
||||
"vite-tsconfig-paths": "5.1.4",
|
||||
"vitest": "2.1.6",
|
||||
"wrangler": "3.109.0"
|
||||
"wrangler": "4.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
_redirects
|
||||
/__redirects
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# homepage
|
||||
/api /api/ 301
|
||||
/docs/ /products/ 301
|
||||
/zero-trust/ /products/?product-group=Cloudflare+One 301
|
||||
/dashboard-landing/ / 301
|
||||
|
|
@ -1911,6 +1912,7 @@
|
|||
/cloudflare-one/tutorials/zsh-env-var/ /cloudflare-one/tutorials/cli/ 301
|
||||
|
||||
### DYNAMIC REDIRECTS ###
|
||||
/api-next/* /api/:splat 301
|
||||
/changelog-next/* /changelog/:splat 301
|
||||
/browser-rendering/quick-actions-rest-api/* /browser-rendering/rest-api/:splat 301
|
||||
/*/sitemap.xml /sitemap-index.xml 301
|
||||
5
public/_headers
Normal file
5
public/_headers
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/*
|
||||
Access-Control-Allow-Origin: *
|
||||
|
||||
/_astro/*
|
||||
Cache-Control: public, max-age=604800, immutable
|
||||
|
|
@ -1,26 +1,12 @@
|
|||
import { WorkerEntrypoint } from "cloudflare:workers";
|
||||
import { generateRedirectsEvaluator } from "redirects-in-workers";
|
||||
import redirectsFileContents from "../dist/_redirects";
|
||||
import redirectsFileContents from "../dist/__redirects";
|
||||
|
||||
const redirectsEvaluator = generateRedirectsEvaluator(redirectsFileContents);
|
||||
|
||||
export default class extends WorkerEntrypoint<Env> {
|
||||
override async fetch(request: Request) {
|
||||
try {
|
||||
try {
|
||||
// Remove once the whacky double-slash rules get removed
|
||||
const url = new URL(request.url);
|
||||
request = new Request(
|
||||
new URL(
|
||||
url.pathname.replaceAll("//", "/") + url.search,
|
||||
"https://developers.cloudflare.com/",
|
||||
),
|
||||
request,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Could not normalize request URL", error);
|
||||
}
|
||||
|
||||
try {
|
||||
// @ts-expect-error Ignore Fetcher type mismatch
|
||||
const redirect = await redirectsEvaluator(request, this.env.ASSETS);
|
||||
|
|
|
|||
2
worker/worker-configuration.d.ts
vendored
2
worker/worker-configuration.d.ts
vendored
|
|
@ -3,7 +3,7 @@
|
|||
interface Env {
|
||||
ASSETS: Fetcher;
|
||||
}
|
||||
declare module "*/_redirects" {
|
||||
declare module "*/__redirects" {
|
||||
const value: string;
|
||||
export default value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ workers_dev = true
|
|||
route = { pattern = "developers.cloudflare.com/*", zone_name = "developers.cloudflare.com"}
|
||||
|
||||
rules = [
|
||||
{ type = "Text", globs = ["**/_redirects"], fallthrough = true },
|
||||
{ type = "Text", globs = ["**/__redirects"], fallthrough = true },
|
||||
]
|
||||
|
||||
[assets]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue