Skip to content

Instantly share code, notes, and snippets.

@IrealiTY
Created November 22, 2024 12:11
Show Gist options
  • Save IrealiTY/24f8eccbfe4386f9c5684c44390e5c46 to your computer and use it in GitHub Desktop.
Save IrealiTY/24f8eccbfe4386f9c5684c44390e5c46 to your computer and use it in GitHub Desktop.
.well-known Cloudflare Worker for bluesky subdomains
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = new URL(request.url)
// Only respond to /.well-known/atproto-did requests
if (url.pathname !== '/.well-known/atproto-did') {
return new Response('Not Found', { status: 404 })
}
// Get subdomain from hostname
const subdomain = url.hostname.split('.')[0]
const didMap = {
'yoursubomain': 'did:plc:your_did_here' // Replace with your actual DID
// Add more subdomains and DIDs as needed
// 'subdomain': 'did:plc:...',
}
if (didMap[subdomain]) {
return new Response(didMap[subdomain], {
headers: {
'Content-Type': 'text/plain',
'Cache-Control': 'max-age=3600'
}
})
}
return new Response('DID not found', {
status: 404,
headers: {
'Content-Type': 'text/plain'
}
})
}
@IrealiTY
Copy link
Author

IrealiTY commented Dec 5, 2024

  1. Visit Cloudflare Dashboard (https://dash.cloudflare.com)
  2. Go to "Workers & Pages"
  3. Click "Create Worker"
  4. Paste in the code above (replace the DID with your actual DID)
  5. Deploy the worker
  6. Go to Settings of the worker
  7. Click +Add on Domains & Routes, add a new Route
  8. Zone, select your domain, Route: *yourdomain.net/.well-known/atproto-did
  9. if not done, create a subdomain for your domain and make sure it's proxied through Cloudfalre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment