post("/send", function (Request $req, Response $response) { $mentioner = new Webmention(); $source = $req->query["source"]; $mentioner->sendForPage($source); }); $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 $e) { $response->status_code = StatusCode::BadRequest; return "Source and target must be valid URLs"; } catch (InvalidTargetException $e) { $response->status_code = StatusCode::BadRequest; return "Target must be on the domain lewisdale.dev"; } catch (\Lewisdale\Webmentions\Exceptions\SourceNotFoundException $e) { $response->status_code = StatusCode::BadRequest; return "Source URL was unreachable"; } catch (\Lewisdale\Webmentions\Exceptions\TargetNotMentionedException) { $response->status_code = StatusCode::BadRequest; return "Source does not mention the target"; } $response->status_code = StatusCode::Created; }); $router->get('/', fn($req, $res) => "

Webmention server

"); $router->dispatch();