Skip to content

FYI lumen does not restrict/register routes by domain #54149

Discussion options

You must be logged in to vote

Solution for domains to work

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class DomainMiddleware
{
    public function handle(Request $request, Closure $next, string $url): mixed
    {
        if ((\parse_url($url)['host'] ?? '*') === $_SERVER['HTTP_HOST'] ?? '*') {
            return $next($request);
        }

        return \response(status: 404);
    }
}


// bootstrap/app.php

$app->routeMiddleware([
    'domain' => \App\Http\Middleware\DomainMiddleware::class,
]);

// routes/web.php

$router->group(
    [
        'middleware' => ['domain:' . (string)\env('APP_URL')],
    ],
    function (Router $router): void {
        $router->post('/login', 'Auth\Auth…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by macropay-solutions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant