refactor: Website/Explorer uses $event->routes() and domain-scoped routing

On explorer.lthn.io: routes serve at root (/). On lthn.io: Mod/Explorer
handles the /explorer prefix. Adopted CorePHP $event->routes() pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude 2026-04-04 09:57:23 +01:00
parent 712a5c56b7
commit c1402cade5
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -13,12 +13,14 @@ use Illuminate\Support\ServiceProvider;
/**
* Block Explorer website.
*
* Serves explorer.lthn.io (prod) or /explorer path on lthn.io.
* On explorer.lthn.io: serves routes at root (/).
* On lthn.io: Mod/Explorer handles /explorer prefix.
*/
class Boot extends ServiceProvider
{
public static array $domains = [
'/^explorer\.lthn\.io$/',
'/^explorer\.(test|localhost)$/',
];
public static array $listens = [
@ -30,8 +32,6 @@ class Boot extends ServiceProvider
public function boot(): void
{
$this->loadViewsFrom(__DIR__ . '/Views', 'explorer');
foreach (static::$listens as $event => $method) {
Event::listen($event, [$this, $method]);
}
@ -47,8 +47,18 @@ class Boot extends ServiceProvider
}
}
public function onWebRoutes(): void
public function onWebRoutes(WebRoutesRegistering $event): void
{
Route::prefix('explorer')->group(__DIR__ . '/Routes/web.php');
$host = $_SERVER['HTTP_HOST'] ?? '';
foreach (static::$domains as $pattern) {
if (preg_match($pattern, $host)) {
// On explorer.lthn.io — serve at root
$event->routes(fn () => Route::group([], __DIR__ . '/Routes/web.php'));
return;
}
}
// On other domains — no routes (Mod/Explorer handles /explorer prefix)
}
}