msfjarvis / msfjarvis.dev

Hugo source for my blog
https://msfjarvis.dev
8 stars 3 forks source link

posts/mastodon-on-your-own-domain-without-hosting-a-server-netlify-edition/ #56

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Mastodon on your own domain without hosting a server, Netlify edition | Harsh Shandilya

A quick and easy way of creating a Fediverse identity on your own domain without an ActivityPub server

https://msfjarvis.dev/posts/mastodon-on-your-own-domain-without-hosting-a-server-netlify-edition/

philwolstenholme commented 1 year ago

Thanks for writing this up :) I copied your approach, but made a change to retrieve the /.well-known/webfinger data from my Mastodon instance directly. Inside the Edge Function I fetch it, then return a modified version of that response. That way, any changes that Hachyderm makes will be reflected in my endpoint, and the headers like content-type: application/jrd+json; charset=utf-8 are retained:

import { Status } from 'https://deno.land/std@0.136.0/http/http_status.ts';

export default async (request, context) => {
  const url = new URL(request.url);
  const resourceParam = url.searchParams.get('resource');

  if (resourceParam === null) {
    return context.json(
      {
        error: "No 'resource' query parameter was provided",
      },
      {
        status: Status.BadRequest,
      }
    );
  }

  if (resourceParam !== 'acct:phil@wolstenhol.me') {
    return context.json(
      {
        error: 'An invalid identity was requested',
      },
      {
        status: Status.BadRequest,
      }
    );
  }

  const webfingerResponse = await fetch('https://hachyderm.io/.well-known/webfinger?resource=acct:philw_@hachyderm.io');
  const json = await webfingerResponse.json();

  json.links.push({
    rel: 'http://webfinger.net/rel/profile-page',
    type: 'text/html',
    href: 'https://wolstenhol.me',
  });

  return new Response(JSON.stringify(json), webfingerResponse);
};
msfjarvis commented 1 year ago

That's quite clever! Thanks for sharing it :D