Created
December 20, 2022 12:32
-
-
Save nkcmr/ca256562ddab6c0a051da29c6ae7445a to your computer and use it in GitHub Desktop.
A Cloudflare worker that allows you to make your domains or email addresses aliases to your Fediverse account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add your domain to CF and assign this worker to a route: example.com/.well-known/webfinger* | |
export default { | |
async fetch(request, env) { | |
return await handleRequest(request); | |
}, | |
}; | |
const lookupmap = { | |
"acct:[email protected]": { | |
self: "https://mastodon.social/users/me_example", | |
profile: "https://mastodon.social/@me_example", | |
}, | |
}; | |
async function handleRequest(request) { | |
const u = new URL(request.url); | |
const resource = (u.searchParams.get("resource") ?? "").toLowerCase().trim(); | |
const result = lookupmap[resource]; | |
if (!result) { | |
return new Response("resource not found", { | |
headers: { "Content-Type": "text/plain" }, | |
status: 404, | |
}); | |
} | |
return new Response( | |
JSON.stringify({ | |
subject: resource, | |
aliases: [ | |
result.profile, | |
result.self, | |
], | |
links: [ | |
{ | |
rel: "http://webfinger.net/rel/profile-page", | |
type: "text/html", | |
href: result.profile, | |
}, | |
{ | |
rel: "self", | |
type: "application/activity+json", | |
href: result.self, | |
}, | |
{ | |
rel: "http://ostatus.org/schema/1.0/subscribe", | |
// replace "mastodon.social" below with your Mastodon instance | |
template: `https://mastodon.social/authorize_interaction?uri={uri}`, | |
}, | |
], | |
}) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment