post("/send", function (Request $req, Response $response) { $mentioner = new Webmention(); $source = $req->query["source"]; try { $mentioner->sendForPage($source); return; } catch (InvalidSourceException $e) { $response->status_code = StatusCode::BadRequest; return $e->getMessage(); } }); $router->post("/endpoint", function (Request $req, Response $response) { $source = $req->post['source']; $target = $req->post['target']; $endpoint = new Endpoint(HttpClient::create(), new SqliteGateway("webmentions.db")); try { $endpoint->receiveWebmention($source, $target); } catch (InvalidUrlException) { $response->status_code = StatusCode::BadRequest; return "Source and target must be valid URLs"; } catch (InvalidTargetException) { $response->status_code = StatusCode::BadRequest; return "Target must be on the domain lewisdale.dev"; } catch (SourceNotFoundException $e) { $response->status_code = StatusCode::BadRequest; return "Source URL was unreachable"; } catch (TargetNotMentionedException) { $response->status_code = StatusCode::BadRequest; return "Source does not mention the target"; } $response->status_code = StatusCode::Created; return; }); $router->get('/', fn($req, $res) => "

Webmention server

"); $router->dispatch();