diff --git a/src/content/docs/learning-paths/mtls/mtls-workers/index.mdx b/src/content/docs/learning-paths/mtls/mtls-workers/index.mdx index 87c64bfc423e0b0..ad2edc8d907576e 100644 --- a/src/content/docs/learning-paths/mtls/mtls-workers/index.mdx +++ b/src/content/docs/learning-paths/mtls/mtls-workers/index.mdx @@ -5,6 +5,8 @@ sidebar: order: 4 --- +import { Tabs, TabItem } from "~/components"; + :::note Cloudflare Workers runs after the Cloudflare WAF and Cloudflare Access. Review the [Traffic Sequence](https://blog.cloudflare.com/traffic-sequence-which-product-runs-first/) visible on the Cloudflare dashboard. ::: @@ -17,6 +19,42 @@ All Client Certificate details can be found in the [tlsClientAuth](/workers/runt Example Cloudflare Workers code to return all headers and gain visibility, including [Client Certificate headers](/ssl/client-certificates/enable-mtls/#cloudflare-workers): + +```js +export default { + async fetch(request, env, ctx) { + const { tlsClientAuth = {} } = request.cf || {}; + const tlsHeaders = { + 'X-CERT-ISSUER-DN': tlsClientAuth.certIssuerDN, + 'X-CERT-SUBJECT-DN': tlsClientAuth.certSubjectDN, + 'X-CERT-ISSUER-DN-L': tlsClientAuth.certIssuerDNLegacy, + 'X-CERT-SUBJECT-DN-L': tlsClientAuth.certSubjectDNLegacy, + 'X-CERT-SERIAL': tlsClientAuth.certSerial, + 'X-CERT-FINGER': tlsClientAuth.certFingerprintSHA1, + 'X-CERT-VERIFY': tlsClientAuth.certVerify, + 'X-CERT-NOTBE': tlsClientAuth.certNotBefore, + 'X-CERT-NOTAF': tlsClientAuth.certNotAfter + }; + + const headers = Object.fromEntries(request.headers); + return new Response(JSON.stringify({ ...headers, ...tlsHeaders }, null, 2), { + headers: { 'Content-Type': 'application/json' } + }); + +} +} + +```` + + + + +:::caution[Service Workers are deprecated] + +Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. + +::: + ```js addEventListener('fetch', event => { event.respondWith( @@ -41,7 +79,10 @@ addEventListener('fetch', event => { })(event.request) ); }); -``` +```` + + + The response when using the browser with a P12 Certificate to visit the mTLS hostname would look similar to this example: diff --git a/src/content/docs/workers/configuration/sites/start-from-existing.mdx b/src/content/docs/workers/configuration/sites/start-from-existing.mdx index 51f56c995d70597..a8b233dc5e69c92 100644 --- a/src/content/docs/workers/configuration/sites/start-from-existing.mdx +++ b/src/content/docs/workers/configuration/sites/start-from-existing.mdx @@ -95,6 +95,12 @@ export default { +:::caution[Service Workers are deprecated] + +Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. + +::: + ```js import { getAssetFromKV } from "@cloudflare/kv-asset-handler"; diff --git a/src/content/docs/workers/examples/cache-using-fetch.mdx b/src/content/docs/workers/examples/cache-using-fetch.mdx index 91eb3637871152e..8dbf4a798f29edb 100644 --- a/src/content/docs/workers/examples/cache-using-fetch.mdx +++ b/src/content/docs/workers/examples/cache-using-fetch.mdx @@ -435,6 +435,12 @@ export default { +:::caution[Service Workers are deprecated] + +Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. + +::: + ```js title="index.js" addEventListener("fetch", (event) => { return event.respondWith(handleRequest(event.request)); diff --git a/src/content/docs/workers/observability/errors.mdx b/src/content/docs/workers/observability/errors.mdx index a1f011dd641b10b..ed95ac8bdc1f9e1 100644 --- a/src/content/docs/workers/observability/errors.mdx +++ b/src/content/docs/workers/observability/errors.mdx @@ -301,6 +301,12 @@ export default { +:::caution[Service Workers are deprecated] + +Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. + +::: + ```js addEventListener("fetch", (event) => { event.respondWith(handleEvent(event)); @@ -342,6 +348,12 @@ export default { +:::caution[Service Workers are deprecated] + +Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. + +::: + ```js addEventListener("fetch", (event) => { event.passThroughOnException(); diff --git a/src/content/docs/workers/observability/logs/workers-logs.mdx b/src/content/docs/workers/observability/logs/workers-logs.mdx index 76a64afbdbb3d6c..97849d8d957e1f2 100644 --- a/src/content/docs/workers/observability/logs/workers-logs.mdx +++ b/src/content/docs/workers/observability/logs/workers-logs.mdx @@ -139,6 +139,12 @@ export default { +:::caution[Service Workers are deprecated] + +Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. + +::: + ```js addEventListener("fetch", (event) => { event.respondWith(handleRequest(event.request)); diff --git a/src/content/docs/workers/reference/migrate-to-module-workers.mdx b/src/content/docs/workers/reference/migrate-to-module-workers.mdx index e4d48bff223ecb5..bb461a2242f91ea 100644 --- a/src/content/docs/workers/reference/migrate-to-module-workers.mdx +++ b/src/content/docs/workers/reference/migrate-to-module-workers.mdx @@ -24,6 +24,12 @@ There are several reasons to migrate your Workers to the ES modules format: The following example demonstrates a Worker that redirects all incoming requests to a URL with a `301` status code. +:::caution[Service Workers are deprecated] + +Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. + +::: + With the Service Worker syntax, the example Worker looks like: ```js diff --git a/src/content/docs/workers/runtime-apis/fetch.mdx b/src/content/docs/workers/runtime-apis/fetch.mdx index 539b374aa3de286..f465ff0bbb9f58c 100644 --- a/src/content/docs/workers/runtime-apis/fetch.mdx +++ b/src/content/docs/workers/runtime-apis/fetch.mdx @@ -45,6 +45,12 @@ export default { +:::caution[Service Workers are deprecated] + +Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. + +::: + ```js null {8} addEventListener('fetch', event => { // NOTE: can’t use fetch here, as we’re not in an async scope yet diff --git a/src/content/docs/workers/runtime-apis/streams/index.mdx b/src/content/docs/workers/runtime-apis/streams/index.mdx index a007716bd867995..40d2855b3ac9848 100644 --- a/src/content/docs/workers/runtime-apis/streams/index.mdx +++ b/src/content/docs/workers/runtime-apis/streams/index.mdx @@ -46,6 +46,12 @@ export default { +:::caution[Service Workers are deprecated] + +Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. + +::: + ```js addEventListener("fetch", (event) => { event.respondWith(fetchAndStream(event.request)); @@ -89,6 +95,12 @@ export default { +:::caution[Service Workers are deprecated] + +Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. + +::: + ```js addEventListener("fetch", (event) => { event.respondWith(fetchAndStream(event.request)); diff --git a/src/content/docs/workers/wrangler/migration/v1-to-v2/wrangler-legacy/configuration.mdx b/src/content/docs/workers/wrangler/migration/v1-to-v2/wrangler-legacy/configuration.mdx index c806b8dab931801..3f0110a4d34837f 100644 --- a/src/content/docs/workers/wrangler/migration/v1-to-v2/wrangler-legacy/configuration.mdx +++ b/src/content/docs/workers/wrangler/migration/v1-to-v2/wrangler-legacy/configuration.mdx @@ -484,6 +484,12 @@ A custom build command for your project. There are two configurations based on t #### Service Workers +:::caution[Service Workers are deprecated] + +Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. + +::: + This section is for customizing Workers with the `service-worker` format. These Workers use `addEventListener` and look like the following: ```js