diff --git a/app/Mod/Chain/Boot.php b/app/Mod/Chain/Boot.php index b983097..96301e0 100644 --- a/app/Mod/Chain/Boot.php +++ b/app/Mod/Chain/Boot.php @@ -14,13 +14,12 @@ class Boot WebRoutesRegistering::class => 'onBoot', ]; - public function onBoot(): void + public function onBoot(WebRoutesRegistering $event): void { app('config')->set('chain', require __DIR__ . '/config.php'); app()->singleton(DaemonRpc::class); app()->singleton(WalletRpc::class); - // Register API auth middleware app('router')->aliasMiddleware('auth.api', \App\Http\Middleware\ApiTokenAuth::class); } } diff --git a/app/Mod/Explorer/Boot.php b/app/Mod/Explorer/Boot.php index 7b6e350..f054a79 100644 --- a/app/Mod/Explorer/Boot.php +++ b/app/Mod/Explorer/Boot.php @@ -13,10 +13,12 @@ class Boot WebRoutesRegistering::class => 'onWebRoutes', ]; - public function onWebRoutes(): void + public function onWebRoutes(WebRoutesRegistering $event): void { - app('view')->addNamespace('explorer', __DIR__ . '/Views'); - Route::prefix('explorer')->group(__DIR__ . '/Routes/web.php'); - Route::prefix('v1/explorer')->group(__DIR__ . '/Routes/api.php'); + $event->views('explorer', __DIR__ . '/Views'); + $event->routes(function () { + Route::prefix('explorer')->group(__DIR__ . '/Routes/web.php'); + Route::prefix('v1/explorer')->group(__DIR__ . '/Routes/api.php'); + }); } } diff --git a/app/Mod/Gateway/Boot.php b/app/Mod/Gateway/Boot.php index 05319c1..a12be4b 100644 --- a/app/Mod/Gateway/Boot.php +++ b/app/Mod/Gateway/Boot.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Mod\Gateway; +use Core\Events\FrameworkBooted; use Core\Events\WebRoutesRegistering; use Illuminate\Support\Facades\Route; use Mod\Gateway\Services\GatewayRegistry; @@ -12,11 +13,16 @@ class Boot { public static array $listens = [ WebRoutesRegistering::class => 'onWebRoutes', + FrameworkBooted::class => 'onFrameworkBooted', ]; - public function onWebRoutes(): void + public function onWebRoutes(WebRoutesRegistering $event): void + { + $event->routes(fn () => Route::prefix('v1/gateway')->group(__DIR__ . '/Routes/api.php')); + } + + public function onFrameworkBooted(FrameworkBooted $event): void { app()->singleton(GatewayRegistry::class); - Route::prefix('v1/gateway')->group(__DIR__ . '/Routes/api.php'); } } diff --git a/app/Mod/Names/Boot.php b/app/Mod/Names/Boot.php index 2d18c2d..9c12959 100644 --- a/app/Mod/Names/Boot.php +++ b/app/Mod/Names/Boot.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Mod\Names; -use Core\Events\ApiRoutesRegistering; use Core\Events\ConsoleBooting; use Core\Events\WebRoutesRegistering; use Illuminate\Support\Facades\Route; @@ -17,20 +16,17 @@ class Boot ConsoleBooting::class => 'onConsole', ]; - public function onWebRoutes(): void + public function onWebRoutes(WebRoutesRegistering $event): void { - app('view')->addNamespace('names', __DIR__ . '/Views'); - Route::prefix('v1/names')->group(__DIR__ . '/Routes/api.php'); - Route::prefix('names')->group(__DIR__ . '/Routes/web.php'); + $event->views('names', __DIR__ . '/Views'); + $event->routes(function () { + Route::prefix('names')->group(__DIR__ . '/Routes/web.php'); + Route::prefix('v1/names')->group(__DIR__ . '/Routes/api.php'); + }); } public function onConsole(ConsoleBooting $event): void { $event->command(RetryDnsTickets::class); } - - public function onApiRoutes(): void - { - Route::prefix('v1/names')->group(__DIR__ . '/Routes/api.php'); - } } diff --git a/app/Mod/Pool/Boot.php b/app/Mod/Pool/Boot.php index 122b7f1..846df99 100644 --- a/app/Mod/Pool/Boot.php +++ b/app/Mod/Pool/Boot.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Mod\Pool; -use Core\Events\ApiRoutesRegistering; +use Core\Events\FrameworkBooted; use Core\Events\WebRoutesRegistering; use Illuminate\Support\Facades\Route; use Mod\Pool\Services\PoolClient; @@ -13,19 +13,20 @@ class Boot { public static array $listens = [ WebRoutesRegistering::class => 'onWebRoutes', - + FrameworkBooted::class => 'onFrameworkBooted', ]; - public function onWebRoutes(): void + public function onWebRoutes(WebRoutesRegistering $event): void + { + $event->routes(function () { + Route::prefix('pool')->group(__DIR__ . '/Routes/web.php'); + Route::prefix('v1/pool')->group(__DIR__ . '/Routes/api.php'); + }); + } + + public function onFrameworkBooted(FrameworkBooted $event): void { app()->singleton(PoolClient::class); app('config')->set('pool', require __DIR__ . '/config.php'); - Route::prefix('v1/pool')->group(__DIR__ . '/Routes/api.php'); - Route::prefix('pool')->group(__DIR__ . '/Routes/web.php'); - } - - public function onApiRoutes(): void - { - Route::prefix('v1/pool')->group(__DIR__ . '/Routes/api.php'); } } diff --git a/app/Mod/Proxy/Boot.php b/app/Mod/Proxy/Boot.php index 3ce87e7..eba5a10 100644 --- a/app/Mod/Proxy/Boot.php +++ b/app/Mod/Proxy/Boot.php @@ -13,8 +13,8 @@ class Boot WebRoutesRegistering::class => 'onWebRoutes', ]; - public function onWebRoutes(): void + public function onWebRoutes(WebRoutesRegistering $event): void { - Route::prefix('v1/proxy')->group(__DIR__ . '/Routes/api.php'); + $event->routes(fn () => Route::prefix('v1/proxy')->group(__DIR__ . '/Routes/api.php')); } } diff --git a/app/Mod/Trade/Boot.php b/app/Mod/Trade/Boot.php index 070e42d..a4f92ec 100644 --- a/app/Mod/Trade/Boot.php +++ b/app/Mod/Trade/Boot.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Mod\Trade; -use Core\Events\ApiRoutesRegistering; use Core\Events\WebRoutesRegistering; use Illuminate\Support\Facades\Route; @@ -12,17 +11,13 @@ class Boot { public static array $listens = [ WebRoutesRegistering::class => 'onWebRoutes', - ]; - public function onWebRoutes(): void + public function onWebRoutes(WebRoutesRegistering $event): void { - Route::prefix('v1/trade')->group(__DIR__ . '/Routes/api.php'); - Route::prefix('trade')->group(__DIR__ . '/Routes/web.php'); - } - - public function onApiRoutes(): void - { - Route::prefix('v1/trade')->group(__DIR__ . '/Routes/api.php'); + $event->routes(function () { + Route::prefix('trade')->group(__DIR__ . '/Routes/web.php'); + Route::prefix('v1/trade')->group(__DIR__ . '/Routes/api.php'); + }); } } diff --git a/app/Website/Api/Boot.php b/app/Website/Api/Boot.php new file mode 100644 index 0000000..4bce1a8 --- /dev/null +++ b/app/Website/Api/Boot.php @@ -0,0 +1,65 @@ + 'onDomain', + WebRoutesRegistering::class => 'onWebRoutes', + ]; + + public function register(): void {} + + public function boot(): void + { + $this->loadViewsFrom(__DIR__ . '/Views', 'api'); + + foreach (static::$listens as $event => $method) { + Event::listen($event, [$this, $method]); + } + } + + public function onDomain(DomainResolving $event): void + { + foreach (static::$domains as $pattern) { + if (preg_match($pattern, $event->domain)) { + $event->resolve($this); + return; + } + } + } + + public function onWebRoutes(WebRoutesRegistering $event): void + { + $host = $_SERVER['HTTP_HOST'] ?? ''; + + foreach (static::$domains as $pattern) { + if (preg_match($pattern, $host)) { + $event->routes(fn () => Route::group([], __DIR__ . '/Routes/web.php')); + return; + } + } + } +} diff --git a/app/Website/Api/Controllers/ApiDocsController.php b/app/Website/Api/Controllers/ApiDocsController.php new file mode 100644 index 0000000..b73d507 --- /dev/null +++ b/app/Website/Api/Controllers/ApiDocsController.php @@ -0,0 +1,20 @@ +name('api.index'); diff --git a/app/Website/Api/Views/index.blade.php b/app/Website/Api/Views/index.blade.php new file mode 100644 index 0000000..50055bd --- /dev/null +++ b/app/Website/Api/Views/index.blade.php @@ -0,0 +1,84 @@ + + +
+ + +REST API for the Lethean .lthn TLD registrar. All endpoints return JSON when called with Accept: application/json.
Base URL: https://api.lthn.io/v1 · Website: lthn.io · Full docs: lthn.io/docs
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/names/available/{name} | Check availability |
| GET | /v1/names/lookup/{name} | Look up registered name |
| GET | /v1/names/directory | All names by type |
| GET | /v1/names/search?q={query} | Search names |
| POST | /v1/names/register | Register a name |
| POST | /v1/names/claim | Pre-register a claim |
| GET | /v1/names/records/{name} | DNS records |
| POST | /v1/names/records/{name} | Update DNS records |
| GET | /v1/names/health | Registrar health |
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/explorer/info | Chain info |
| GET | /v1/explorer/stats | Chain statistics |
| GET | /v1/explorer/block/{id} | Block by height or hash |
| GET | /v1/explorer/aliases | All chain aliases |
| GET | /v1/explorer/alias/{name} | Alias details |
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/proxy/status | Network availability + pricing |
| GET | /v1/proxy/nodes | List nodes by capability |
| POST | /v1/proxy/connect | Get gateway connection |
| Method | Endpoint | Description |
|---|---|---|
| POST | /v1/gateway/pair | Pair a gateway node |
| POST | /v1/gateway/heartbeat | Report alive + stats |
| GET | /v1/gateway/live | Live paired gateways |
Read endpoints (GET) are public. Write endpoints (POST) require Authorization: Bearer {token}. Get keys at order.lthn.ai.