FYI lumen does not restrict/register routes by domain #54149
Answered
by
macropay-solutions
macropay-solutions
asked this question in
General
-
This will work on any domain pointing to the app not just on APP_URL. It is just FYI, not a bug. $router->group(
[
'domain' => (string)\env('APP_URL'),
],
function (Router $router): void {
$router->post('/login', 'Auth\AuthController@login');
}
); To test it you can put: $router->group(
[
'domain' => 'https://example.com', // call it on https://yourwebsite.com/login and it will work (in laravel it will not).
],
function (Router $router): void {
$router->post('/login', 'Auth\AuthController@login');
}
); and it will work. |
Beta Was this translation helpful? Give feedback.
Answered by
macropay-solutions
Jan 10, 2025
Replies: 1 comment
-
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\AuthController@login');
}
); |
Beta Was this translation helpful? Give feedback.
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
Solution for domains to work