Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api group 404 not found #1768

Open
mk-fangkuai opened this issue Jan 17, 2021 · 10 comments
Open

Api group 404 not found #1768

mk-fangkuai opened this issue Jan 17, 2021 · 10 comments

Comments

@mk-fangkuai
Copy link

mk-fangkuai commented Jan 17, 2021

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 8.12
Package version 3.0.5
PHP version 8.0.1

1223/5000

Actual behavior

api.php

$api = app('Dingo\Api\Routing\Router');

$api->group(["version"=>"v1","namespace"=>"\App\Http\Controllers\Admin","prefix"=>"admin"], function ($api) {

$api->get("login","LoginController@login")->name("admin.login");

});

404 not found

sail@caca0a954c1f:/var/www/html$ php artisan api:routes

+------+----------+-------------+-------------+--------------------------------------------------+-----------+------------+----------+------------+

| Host | Method | URI | Name | Action | Protected | Version(s) | Scope(s) | Rate Limit |

+------+----------+-------------+-------------+--------------------------------------------------+-----------+------------+----------+------------+

| | GET|HEAD | admin/login | admin.login | App\Http\Controllers\Admin\LoginController@login | No | v1 | | |

+------+----------+-------------+-------------+--------------------------------------------------+-----------+------------+----------+------------+

@fredroo
Copy link

fredroo commented Feb 23, 2021

same problem, api group return 404 after migration from laravel 5.8 to 6, dingo api 2.4.7 from 2.3.0

@specialtactics
Copy link
Member

Hey, can you please post your http Kernel.php file?

@fredroo
Copy link

fredroo commented Apr 30, 2021

In my case solve by domain in .env

@ALTELMA
Copy link

ALTELMA commented Jul 14, 2021

@fredroo Do you mean API_DOMAIN, right? @specialtactics This problem cause sometimes. I really want to know for where to debug or checking first.

In my case when I using same configuration, but different environment, domain etc.

Domain is the one factor to made route always return 404, right?

Is it possible to share dingo API logic for routing?

@fredroo
Copy link

fredroo commented Jul 14, 2021

@ALTELMA yes

@ALTELMA
Copy link

ALTELMA commented Jul 14, 2021

Thanks for your suggestion @fredroo. My case depends on the configuration of the server, but it can end the problem as you mentioned. Normally I using Nginx for proxy and API_DOMAIN related to the internal proxy_pass such as order-service, payment-service. When I try to change to use Ingress Nginx Controller API_DOMAIN should replace by a real domain.

Hopefully, this helps someone fix your problem.

@bm2ilabs
Copy link

Thanks @fredroo indeed it was the issue

@specialtactics
Copy link
Member

Hey @ALTELMA

Is it possible to share dingo API logic for routing?

Yes, this logic is in the code which is shared via this repository 😛

@RajuPuthen
Copy link

@specialtactics , I am also facing the same issue. I am getting 404 error for my API routes. Other routes are working fine.

"php artisan api:routes" command would list all API routes, but those returning 404. Any suggestion would be appreciated.

I am using below configuration values in my .env file

API_PREFIX=
API_DOMAIN=localhost

My kernal.php file is below,

protected $middleware = [
//\Fruitcake\Cors\HandleCors::class,
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];

protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

    'api' => [
        // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
        'throttle:api',
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],
];

protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];

@specialtactics
Copy link
Member

@RajuPuthen plz post your HTTP kernel file and env file and what is the URL you are using to access them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants