Keep the raw worker URL pointed at the canonical site
Some checks failed
Deploy to Cloudflare Workers with Wrangler / Deploy (push) Has been cancelled
Run Node 24 Checks / build (24.x) (push) Has been cancelled

The default worker is published to workers.dev, but fetching that hostname as the origin returns Cloudflare's placeholder page. Redirect the raw workers.dev host to doesitarm.com while keeping the existing pass-through behavior for routed custom hosts.

Constraint: workers.dev has no real site origin behind the default worker
Rejected: Proxy workers.dev through doesitarm.com | redirect is simpler and avoids presenting duplicate public hosts
Confidence: high
Scope-risk: narrow
Directive: Keep this redirect host-specific so custom-domain worker routes can continue pass-through behavior
Tested: npm --prefix doesitarm-default run build
Not-tested: Post-deploy live redirect, pending GitHub Actions deployment
This commit is contained in:
Sam Carlton 2026-04-26 12:53:35 -05:00
parent d1f49267c0
commit 81b2179d0f

View file

@ -16,10 +16,33 @@ addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const canonicalHost = 'doesitarm.com'
const workersDevHost = 'doesitarm-default.samcarlton.workers.dev'
const workerHeaderName = 'x-workers-hello'
const workerHeaderValue = 'Hello from Cloudflare Workers'
function redirectToCanonicalHost(url) {
url.protocol = 'https:'
url.hostname = canonicalHost
return new Response(null, {
headers: {
Location: url.toString(),
[workerHeaderName]: workerHeaderValue
},
status: 302
})
}
// Alter Headers - https://developers.cloudflare.com/workers/examples/alter-headers
async function handleRequest(request) {
// const visitor = ua( process.env.GA_TRACKING_ID )
const url = new URL(request.url)
if (url.hostname === workersDevHost) {
return redirectToCanonicalHost(url)
}
const response = await fetch(request)
@ -28,7 +51,7 @@ async function handleRequest(request) {
const newResponse = new Response(response.body, response)
// Add a custom header with a value
newResponse.headers.append("x-workers-hello", "Hello from Cloudflare Workers")
newResponse.headers.append(workerHeaderName, workerHeaderValue)
// // Delete headers
// newResponse.headers.delete("x-header-to-delete")