load(); $router = new Router(); $gateway = new SqliteGateway($_ENV["DB"]); $apiController = new WebmentionApi($gateway); $router->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) use ($gateway) { $source = $req->post['source']; $target = $req->post['target']; $endpoint = new Endpoint(HttpClient::create(), $gateway); try { $id = $endpoint->receiveWebmention($source, $target); $response->header('Location', "/webmention/" . $id); $response->status_code = StatusCode::Created; } 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"; } }); $router->get('/webmention/(\d+)', [$apiController, "get"]); $router->get('/', fn($req, $res) => "