Skip to content

Instantly share code, notes, and snippets.

@mbbx6spp
Last active November 24, 2022 18:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbbx6spp/2c0873c24dd9c7d417cea98b87eaf11e to your computer and use it in GitHub Desktop.
Save mbbx6spp/2c0873c24dd9c7d417cea98b87eaf11e to your computer and use it in GitHub Desktop.
# make sure you put this in the root of the generate site build, not just in the root of your netlify repository!
/.well-known/webfinger* https://APPNAME.deno.dev/:splat 200
import { serve } from "https://deno.land/std@0.140.0/http/server.ts";
serve((req) => {
const url = new URL(req.url);
const resource = url.searchParams.get('resource') || 'acct:SusanPotter@mastodon.social';
const rel = url.searchParams.get('rel');
console.log({resource, rel, url: url.toString(), headers: { "X-From": req.headers.get('X-From') } });
return new Response(
JSON.stringify(getSubjectByRel(resource, rel)),
{ headers: { "content-type": "application/json" } }
);
});
const getSubjectByRel = (subject, rel) => {
const entry = subjects[subject];
const filteredLinks = rel ? entry.links.filter(link => link.rel == rel) : entry.links;
return { subject: entry.subject, aliases: entry.aliases, links: filteredLinks, };
};
const mastodonDocument = {
"subject": "acct:SusanPotter@mastodon.social",
"aliases": [
"https://mastodon.social/@SusanPotter",
"https://mastodon.social/users/SusanPotter"
],
"links": [
{
"rel": "http://webfinger.net/rel/profile-page",
"type": "text/html",
"href": "https://mastodon.social/@SusanPotter"
},
{
"rel": "self",
"type": "application/activity+json",
"href": "https://mastodon.social/users/SusanPotter"
},
{
"rel": "http://ostatus.org/schema/1.0/subscribe",
"template": "https://mastodon.social/authorize_interaction?uri={uri}"
}
]
};
const subjects = {
"acct:SusanPotter@mastodon.social": mastodonDocument,
"acct:me@susanpotter.net": mastodonDocument,
"acct:SusanPotter@susanpotter.net": mastodonDocument,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment