title = "Mastodon on your own domain without hosting a server, Netlify edition"
+++
## Preface
I recently came across [a blog post](https://blog.maartenballiauw.be/post/2022/11/05/mastodon-own-donain-without-hosting-server.html) from [Maarten Balliauw](https://mastodon.online/@maartenballiauw) that explained how they had managed to create an ActivityPub compatible identity for themselves, without hosting Mastodon or any other ActivityPub server.
I recommend going to their blog and reading the whole thing, but here's a TL;DR
- [ActivityPub](https://activitypub.rocks/) has the notion of an "actor" that sends messages
- This "actor" must be discoverable via a protocol called [WebFinger](https://webfinger.net)
- WebFinger is ridiculously easy to implement
For all practical purposes, WebFinger is essentially a JSON document that is served at `/.well-known/webfinger` from a domain and is used to identify "actors" across the Fediverse.
Maarten's approach to implementing this was to simply place the JSON document at `/.well-known/webfinger` on their domain `balliauw.be`, which allowed `@maarten@balliauw.be` to become a WebFinger-compatible identity that can be searched for on Mastodon and will return their actual `@maartenballiauw.be@mastodon.online` profile.
Maarten did however note that since they're relying on static hosting, they're unable to restrict what identities they can enforce as valid, and thus a search for `@anything@balliauw.be` will also return their `mastodon.online` identity.
## The implementation
I wanted to also set up something like this, but without the limitation Maarten had run into. Since my website runs on Netlify, I decided to try out using an [Edge Function](https://docs.netlify.com/edge-functions/overview/) to build this up.
Similar to Maarten, I first obtained my current Fediverse identity from the Mastodon server I am on: [androiddev.social](https://androiddev.social) (incredible props to [Mikhail](https://androiddev.social/@friendlymike) for making it a reality).
? Select the type of function you'd like to create: Edge function (Deno)
? Select the language of your function: TypeScript
? Pick a template: typescript-json
? Name your function: webfinger
◈ Creating function webfinger
◈ Created netlify/edge-functions/webfinger/webfinger.ts
? What route do you want your edge function to be invoked on?: /.well-known/webfinger
◈ Function 'webfinger' registered for route `/.well-known/webfinger`. To change, edit your `netlify.toml` file.
```
Next, add the following code to the TypeScript file just created for you. I've added comments inline to explain what each part of the code does so you can customize it according to your needs.
```typescript
// Netlify Edge Functions run on Deno (https://deno.land), so imports use URLs rather than package names.
import { Status } from "https://deno.land/std@0.136.0/http/http_status.ts";
import type { Context } from "https://edge.netlify.com";