0

I have an application in Laravel deployed on the server. When I try to call POST in Postman:

http://api.mydomain.com/api/auth/signin

I get the error 404 not found.

In file RouteServiceProvider I commented section for web:

public function boot()
    {
        $this->configureRateLimiting();

        $this->routes(function () {
            Route::prefix('api')
                ->middleware('api')
                ->namespace($this->namespace)
                ->group(base_path('routes/api.php'));
            /*
            Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));
            */
        });
    }

When I had uncommented section for web and send GETfrom Postman but without any suffix, only domain: api.mydomain.com/ it worked. Now I commented web and have only API section and any request to API method doesn't work. My controller:

class JwtAuthController extends Controller
{
    //
    public function __construct() {
        $this->middleware('auth:api', ['except' => ['login', 'register']]);
    }

    /**
     * Get a JWT via given credentials.
    */
    public function login(Request $request){
...
}

In api.php file:

Route::group([
    'middleware' => 'api',
    'prefix' => 'auth'
], function ($router) {
    Route::post('/signin', [JwtAuthController::class, 'login']);
}

Result for php artisan route:list:

| App\Http\Middleware\Authenticate:api |
|        
| POST     
| api/auth/signin                                                             
| generated::1YOyMAVvTTnBZtym 
| App\Http\Controllers\JwtAuthController@login                        
| api  

                            

On my local machine, it works, but when I deploy it on the server it won't work.

1 Answer 1

1

Not found because you did not add the subdomain api, To fix it

You can just remove api. from url, like that http://exmaple.com/api/auth/signin

OR

you can add the subdomain to RouteServiceProvider

like that

 Route::middleware('api')
    ->prefix('api')
    ->domain('api.exmaple.com') // <-
    ->namespace($this->namespace)
    ->group(base_path('routes/api.php'));

Sign up to request clarification or add additional context in comments.

2 Comments

When I try in Postman with this url: http://api.mydomaincom/auth/signin I get 404, I added ->domain('api.mydomain.com') and still the same error
@Mark did you clear the config?, you must remove ->prefix('api') from RouteServiceProvider btw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.