Skip to content

Instantly share code, notes, and snippets.

@nkcmr
Created December 20, 2022 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkcmr/ca256562ddab6c0a051da29c6ae7445a to your computer and use it in GitHub Desktop.
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
// 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:me@example.com": {
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