Skip to content
Merged
Changes from all 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
16 changes: 10 additions & 6 deletions src/content/partials/workers/custom_headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,20 @@ To enable other domains to fetch every static asset from your {props.product ===
Access-Control-Allow-Origin: *
```

This applies the `Access-Control-Allow-Origin` header to any incoming URL. To be more restrictive, you can define a URL pattern that applies to a <code>{props.product === 'workers' ? '\*.\*.workers.dev' : '\*.pages.dev'}</code> subdomain, which then only allows access from its {props.product === 'workers' ? <a href="/workers/configuration/previews/">preview URLs</a> : <><code>staging</code> branch's subdomain</>}:
{props.product === "workers" ? (
<>
This applies the `Access-Control-Allow-Origin` header to any incoming URL. Note that the CORS specification only allows `*`, `null`, or an exact origin as valid `Access-Control-Allow-Origin` values — wildcard patterns within origins are not supported. To allow CORS from specific <a href="/workers/configuration/previews/">preview URLs</a>, you will need to handle this dynamically in your Worker code rather than through the `_headers` file.
</>
) : (
<>
This applies the `Access-Control-Allow-Origin` header to any incoming URL. To be more restrictive, you can define a URL pattern that applies to a <code>{'\*.pages.dev'}</code> subdomain, which then only allows access from its <code>staging</code> branch's subdomain:

<Code
lang="txt"
code={
props.product === "workers"
? `https://:worker.:subdomain.workers.dev/*\n\tAccess-Control-Allow-Origin: https://*-:worker.:subdomain.workers.dev/`
: `https://:project.pages.dev/*\n\tAccess-Control-Allow-Origin: https://staging.:project.pages.dev/`
}
code={`https://:project.pages.dev/*\n\tAccess-Control-Allow-Origin: https://staging.:project.pages.dev/`}
/>
</>
)}

##### Prevent your workers.dev URLs showing in search results

Expand Down