Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publish-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-22.04
permissions:
contents: read
name: Publish to Cloudflare Pages (Preview)
name: Publish Preview
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -35,7 +35,7 @@ jobs:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- run: npm run build:worker && npx wrangler versions upload -c ./wrangler-workers.toml
name: Deploy to Cloudflare Workers [preview]
name: Deploy to Cloudflare Workers
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- uses: actions/cache/save@v4
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/publish-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-22.04
permissions:
contents: read
name: Publish to Cloudflare Pages (Production)
name: Publish Production
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -30,6 +30,10 @@ jobs:
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- run: npx wrangler deploy -c ./wrangler-workers.toml
name: Deploy to Cloudflare Workers
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- uses: actions/cache/save@v4
if: always()
with:
Expand Down
15 changes: 7 additions & 8 deletions public/_redirects
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
/d1/reference/query-json/ /d1/build-with-d1/query-json/ 301
/d1/configuration/local-development/ /d1/build-with-d1/local-development/ 301
/d1/configuration/remote-development/ /d1/build-with-d1/remote-development/ 301
/d1/build-with-d1/import-data/ /d1/build-with-d1/import-export-data/ 301
/d1/build-with-d1/import-data/ /d1/build-with-d1/import-export-data/ 301
/d1/reference/database-commands/ /d1/reference/sql-statements/ 301

# data loss prevention (dlp)
Expand Down Expand Up @@ -702,7 +702,6 @@
/logs/reference/logpush-api-configuration/ /logs/get-started/api-configuration/ 301
/logs/reference/logpush-api-configuration/filters/ /logs/reference/filters/ 301
# Non-slashed version is being used in the Cloudflare dashboard
/logs/reference/logpush-api-configuration/custom-fields /logs/reference/custom-fields/ 301
/logs/reference/logpush-api-configuration/custom-fields/ /logs/reference/custom-fields/ 301
/logs/reference/logpush-api-configuration/examples/example-logpush-curl/ /logs/tutorials/examples/example-logpush-curl/ 301

Expand Down Expand Up @@ -1400,9 +1399,9 @@
/workers/platform/logpush/ /workers/observability/logging/logpush/ 301
/workers/observability/logpush/ /workers/observability/logging/logpush/ 301
/workers/platform/tail-workers/ /workers/observability/logging/tail-workers/ 301
/workers/observability/tail-workers/ /workers/observability/logging/tail-workers/ 301
/workers/errors/script-will-never-generate-a-response/ /workers/observability/errors/#the-script-will-never-generate-a-response-errors 301
/workers/errors/illegal-invocation/ /workers/observability/errors/#illegal-invocation-errors 301
/workers/observability/tail-workers/ /workers/observability/logging/tail-workers/ 301
/workers/errors/script-will-never-generate-a-response/ /workers/observability/errors/#the-script-will-never-generate-a-response-errors 301
/workers/errors/illegal-invocation/ /workers/observability/errors/#illegal-invocation-errors 301
/workers/learning/metrics-and-analytics/ /workers/observability/metrics-and-analytics/ 301
/workers/learning/integrations/databases/ /workers/databases/connecting-to-databases/ 301
/workers/learning/how-routing-works/ /workers/platform/routing/ 301
Expand Down Expand Up @@ -1461,6 +1460,7 @@
/workers/runtime-apis/queues/ /workers/runtime-apis/bindings/bindings/queues/ 301
/workers/runtime-apis/service-bindings/ /workers/runtime-apis/bindings/service-bindings/ 301
/workers/observability/local-development-and-testing/ /workers/testing/local-development/ 301
/workers/observability/sentry-integration/ /workers/observability/integrations/sentry 301
/workers/configuration/deployments/ /workers/configuration/versions-and-deployments/ 301
/workers/configuration/continuous-integration/ /workers/ci-cd/ 301
/workers/wrangler/ci-cd/ /workers/ci-cd/external-cicd/ 301
Expand All @@ -1480,7 +1480,7 @@
/workers-ai/models/embedding/ /workers-ai/models/#text-embeddings 301
/workers-ai/models/text-embeddings/ /workers-ai/models/#text-embeddings 301
/workers-ai/models/speech-recognition/ /workers-ai/models/#automatic-speech-recognition 301
/workers-ai/models/translation/ /workers-ai/models/#translation 301
/workers-ai/models/translation/ /workers-ai/models/#translation 301
/workers-ai/models/text-classification/ /workers-ai/models/#text-classification 301
/workers-ai/models/image-classification/ /workers-ai/models/#image-classification 301
/workers-ai/models/codellama-7b-instruct-awq/ /workers-ai/models/ 301
Expand Down Expand Up @@ -1657,7 +1657,7 @@
/cloudflare-one/policies/zero-trust/ /cloudflare-one/policies/access/ 301
/cloudflare-one/policies/zero-trust/app-paths/ /cloudflare-one/policies/access/app-paths/ 301
/cloudflare-one/policies/zero-trust/common-configs/ /cloudflare-one/policies/access/ 301
/cloudflare-one/policies/zero-trust/cors/ /cloudflare-one/identity/authorization-cookie/cors/ 301
/cloudflare-one/policies/zero-trust/cors/ /cloudflare-one/identity/authorization-cookie/cors/ 301
/cloudflare-one/policies/zero-trust/temporary-auth/ /cloudflare-one/policies/access/temporary-auth/ 301
/cloudflare-one/policies/filtering/dns-policies-builder/dns-categories/ /cloudflare-one/policies/gateway/domain-categories/ 301
/cloudflare-one/policies/filtering/dns-policies/dns-categories/ /cloudflare-one/policies/gateway/domain-categories/ 301
Expand Down Expand Up @@ -1811,7 +1811,6 @@
# Workers
/workers/reference/apis/* /workers/runtime-apis/:splat 301
/workers/templates/pages/* /workers/examples/:splat 301
/workers/observability/sentry-integration /workers/observability/integrations/sentry 301
/workers/observability/logging/* /workers/observability/logs/:splat 301

# Others
Expand Down
55 changes: 51 additions & 4 deletions worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,58 @@ 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;
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 {
const redirect = await redirectsEvaluator(request, this.env.ASSETS);
if (redirect) {
return redirect;
}
} catch (error) {
console.error("Could not evaluate redirects", error);
}

try {
const forceTrailingSlashURL = new URL(
request.url.replace(/([^/])$/, "$1/"),
request.url,
);
const redirect = await redirectsEvaluator(
new Request(forceTrailingSlashURL, request),
this.env.ASSETS,
);
if (redirect) {
return redirect;
}
} catch (error) {
console.error(
"Could not evaluate redirects with a forced trailing slash",
error,
);
}

try {
return await functions.fetch(request, this.env, this.ctx);
} catch (error) {
console.error("Could not evaluate functions", error);
}
} catch (error) {
console.error("Unknown error", error);
}

return await functions.fetch(request, this.env, this.ctx);
return this.env.ASSETS.fetch(request);
}
}
4 changes: 4 additions & 0 deletions wrangler-workers.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#:schema ./node_modules/wrangler/config-schema.json
name = "cloudflare-docs"
account_id = "b54f07a6c269ecca2fa60f1ae4920c99"
compatibility_date = "2022-09-27"
main = "./worker/index.ts"

workers_dev = true
route = { pattern = "developers.cloudflare.com/*", zone_name = "developers.cloudflare.com"}

rules = [
{ type = "Text", globs = ["**/_redirects"], fallthrough = true },
]
Expand Down
2 changes: 1 addition & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#:schema ./node_modules/wrangler/config-schema.json
name = "cloudflare-docs"
compatibility_date = "2022-09-27"

Loading