Api: Regular Laravel routes returns 404 after update

Created on 29 Mar 2016  路  16Comments  路  Source: dingo/api

I've updated Dingo to the latest version using "dingo/api": "1.0.*@dev", but now all my regular Laravel routes outside the Dingo router won't seem to match any requests. Even a simple route isn't recognized as a valid request:

Route::get('test', function() {
    die('test');
});

Can u look at this problem?

Most helpful comment

I'm having the same issue锛宎fter update appear this question

{"message":"404 Not Found","status_code":404,"debug":{"line":161,"file":"\/www\/personalpushcenter\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/RouteCollection.php","class":"Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException","trace":["#0 \/www\/personalpushcenter\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Router.php(750): Illuminate\\Routing\\RouteCollection->match(Object(Dingo\\Api\\Http\\Request))",

The problem is API_DOMAIN in .env or config/api.php file.
i modified the value of API_DOMAIN to empty ,and solve the problem.
which is like:

API_STANDARDS_TREE=vnd
API_SUBTYPE=myapp
API_VERSION=v1
API_PREFIX=api
API_DOMAIN=
API_NAME=My API
API_CONDITIONAL_REQUEST=false
API_STRICT=false
API_DEBUG=true
API_DEFAULT_FORMAT = json
API_TRANSFORMER = Dingo\Api\Transformer\Adapter\Fractal

All 16 comments

What version did you update from? What version of Laravel? Is the error a JSON 404 response?

I don't know the specific version i came from, the v1.0.0-beta3 is working correctly.
The response is JSON:

{ "message": "404 Not Found" }

My Laravel version is: 5.2.26

Hm, still hard to really determine what the cause could be. Routes are working fine on my end running the same Laravel version.

Other things to check are how you've configured your API, and also try to replicate in a clean install of Laravel. If you can replicate it in a clean install provide the code you used so I can give it a whirl.

I am also facing the same problem after the upgrade. /home and /login no longer working.
It seems to be going to Dingo even for normal Routes.

My .env
API_VERSION=v1
API_PREFIX=/api/
API_DEFAULT_FORMAT=json
API_DEBUG=true

Below is the trace:

 {"message":"404 Not Found","status_code":404,"debug":
 {"line":161,"file":"D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\RouteCollection.php",
 "class":"Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
 "trace":["#0 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(823): 
 Illuminate\\Routing\\RouteCollection->match(Object(Dingo\\Api\\Http\\Request))",
 "#1 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(691): 
 Illuminate\\Routing\\Router->findRoute(Object(Dingo\\Api\\Http\\Request))",
 "#2 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(675): 
 Illuminate\\Routing\\Router->dispatchToRoute(Object(Dingo\\Api\\Http\\Request))",
 "#3 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\dingo\\api\\src\\Routing\\Adapter\\Laravel.php(80): 
 Illuminate\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))",
 "#4 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\dingo\\api\\src\\Routing\\Router.php(574): 
 Dingo\\Api\\Routing\\Adapter\\Laravel->dispatch(Object(Dingo\\Api\\Http\\Request), 'v1')",
 "#5 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\dingo\\api\\src\\Http\\Middleware\\Request.php(123): 
 Dingo\\Api\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))",
 "#6 [internal function]: Dingo\\Api\\Http\\Middleware\\Request->Dingo\\Api\\Http\\Middleware\\{closure}(Object(Dingo\\Api\\Http\\Request))",
 "#7 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(139): 
 call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))",
 "#8 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php(44): 
 Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
 "#9 [internal function]: Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))",
 "#10 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(124): call_user_func_array(Array, Array)",
 "#11 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
 "#12 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(103): 
 call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))",
 "#13 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\dingo\\api\\src\\Http\\Middleware\\Request.php(124): 
 Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
 "#14 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\dingo\\api\\src\\Http\\Middleware\\Request.php(100): 
 Dingo\\Api\\Http\\Middleware\\Request->sendRequestThroughRouter(Object(Dingo\\Api\\Http\\Request))",
 "#15 [internal function]: Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Illuminate\\Http\\Request), Object(Closure))",
 "#16 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(124): call_user_func_array(Array, Array)",
 "#17 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
 "#18 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(32): 
 call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
 "#19 [internal function]: Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))",
 "#20 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(103): 
 call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
 "#21 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(132): 
 Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
 "#22 D:\\PHP\\sublimeWSpace\\aibim\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(99): 
 Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))",
 "#23 D:\\PHP\\sublimeWSpace\\aibim\\public\\index.php(54): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))",
 "#24 D:\\PHP\\sublimeWSpace\\aibim\\server.php(21): require_once('D:\\\\PHP\\\\sublimeW...')","#25 {main}"]}}

I'm having the same issue, looks line all Laravel routes are returning a 404 error: {"message":"404 Not Found","status_code":404}

I've tried a clean install of Laravel 5.2.26 and Dingo dev-master f985637 but still the same issue:

{
    "message": "404 Not Found",
    "debug": {
        "line": 161,
        "file": "/home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php",
        "class": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
        "trace": [
            "#0 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Routing/Router.php(823): Illuminate\\Routing\\RouteCollection->match(Object(Dingo\\Api\\Http\\Request))",
            "#1 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Routing/Router.php(691): Illuminate\\Routing\\Router->findRoute(Object(Dingo\\Api\\Http\\Request))",
            "#2 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Routing/Router.php(675): Illuminate\\Routing\\Router->dispatchToRoute(Object(Dingo\\Api\\Http\\Request))",
            "#3 /home/vagrant/Code/helloocloud/vendor/dingo/api/src/Routing/Adapter/Laravel.php(65): Illuminate\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))",
            "#4 /home/vagrant/Code/helloocloud/vendor/dingo/api/src/Routing/Router.php(559): Dingo\\Api\\Routing\\Adapter\\Laravel->dispatch(Object(Dingo\\Api\\Http\\Request), 'v1')",
            "#5 /home/vagrant/Code/helloocloud/vendor/dingo/api/src/Http/Middleware/Request.php(112): Dingo\\Api\\Routing\\Router->dispatch(Object(Dingo\\Api\\Http\\Request))",
            "#6 [internal function]: Dingo\\Api\\Http\\Middleware\\Request->Dingo\\Api\\Http\\Middleware\\{closure}(Object(Dingo\\Api\\Http\\Request))",
            "#7 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))",
            "#8 /home/vagrant/Code/helloocloud/app/Http/Middleware/DreddMiddleware.php(51): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
            "#9 [internal function]: App\\Http\\Middleware\\DreddMiddleware->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))",
            "#10 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)",
            "#11 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(44): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
            "#12 [internal function]: Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))",
            "#13 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)",
            "#14 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Dingo\\Api\\Http\\Request))",
            "#15 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Dingo\\Api\\Http\\Request))",
            "#16 /home/vagrant/Code/helloocloud/vendor/dingo/api/src/Http/Middleware/Request.php(113): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
            "#17 /home/vagrant/Code/helloocloud/vendor/dingo/api/src/Http/Middleware/Request.php(89): Dingo\\Api\\Http\\Middleware\\Request->sendRequestThroughRouter(Object(Dingo\\Api\\Http\\Request))",
            "#18 [internal function]: Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Dingo\\Api\\Http\\Request), Object(Closure))",
            "#19 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)",
            "#20 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))",
            "#21 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
            "#22 [internal function]: Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))",
            "#23 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))",
            "#24 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(132): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))",
            "#25 /home/vagrant/Code/helloocloud/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(99): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))",
            "#26 /home/vagrant/Code/helloocloud/public/index.php(53): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))",
            "#27 {main}"
        ]
    }
}

The code I use is:

Route::get('test', function() {
    die('test');
});

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

# Routes version 1
$api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($api) {
    $api->get('test2', function() {
         die('test2');
    });
});

Before my regular Laravel routes and the Dingo routes where working perfectly next to each other.

I'm having the same issue锛宎fter update appear this question

{"message":"404 Not Found","status_code":404,"debug":{"line":161,"file":"\/www\/personalpushcenter\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/RouteCollection.php","class":"Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException","trace":["#0 \/www\/personalpushcenter\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Router.php(750): Illuminate\\Routing\\RouteCollection->match(Object(Dingo\\Api\\Http\\Request))",

The problem is API_DOMAIN in .env or config/api.php file.
i modified the value of API_DOMAIN to empty ,and solve the problem.
which is like:

API_STANDARDS_TREE=vnd
API_SUBTYPE=myapp
API_VERSION=v1
API_PREFIX=api
API_DOMAIN=
API_NAME=My API
API_CONDITIONAL_REQUEST=false
API_STRICT=false
API_DEBUG=true
API_DEFAULT_FORMAT = json
API_TRANSFORMER = Dingo\Api\Transformer\Adapter\Fractal

@hananfauzi Remove the / from around API_PREFIX.

@njansenNL Copied your code exactly and it works fine. I'm using the following config in .env.

API_VERSION=v1
API_PREFIX=api
API_DEBUG=true

Please confirm your config.

@LiangJianle Don't even define it in .env if you're not setting it. Just remove it entirely. The only time you should be using API_DOMAIN is if you wish to configure the API to run under a subdomain. Otherwise just use a prefix.

@jasonlewis if set API_DOMAIN options such as xxx.xxx.com in .env file, the same "404 not Found " problem as @njansenNL commented above will arise, pls help to give some suggestions, thx.

Please can you push this code somewhere so I can test it out.

My .env:

API_VERSION=v1
API_DOMAIN=api.laravelfivetwo.app
API_DEBUG=true

Routes:

Route::get('test', function() {
    die('test');
});

app('Dingo\Api\Routing\Router')->version('v1', function ($api) {
    $api->get('test2', function() {
        die('test2');
    });
});

Visiting api.laravelfivetwo.app/test produces expected 404.
Visiting api.laravelfivetwo.app/test2 produces expected test2.
Visiting laravelfivetwo.app/test produces expected test.

As far as I can see everything is working fine. So please, please, can someone that's having these issues recreate this EXACT issue on a fresh install and throw it up on GitHub.

Because something is clearly missing here and as of yet I'm not convinced there's an actual issue.

@jasonlewis I'm sorry, very busy @ work, today i didn't have time to create fresh installation and throw it up on Github.
Why does the /test route produces an expected 404? I want to have some routes outside the versioning of the API-routes, just like the test-route.

@njansenNL You can, they just can't be on the sub-domain. I'm not really sure why you'd want an API sub-domain to have regular Laravel routes anyway? Seems a bit odd.

You can still have regular routes they'll just be accessible through the regular domain, not the sub-domain.

I've noticed a difference in behavior with the latest Dingo commit and routing too. Specifically, I had my routes file looking something like this:

Route::post('api/auth', 'Api\V1\AuthenticateController@authenticate');
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['middleware' => 'api.auth'], function ($api) {
    $api->resource('users', 'App\Http\Controllers\Api\V1\UserController');
});

with .env file with the following settings:

API_PREFIX=api
API_VERSION=v1
API_STRICT=false
API_DEBUG=true

After the most recent Dingo commit, my route to api/auth would return a 404 instead of routing to the AuthenticateController. I found that if I changed the API_PREFIX in my .env file to /api/ (with slashed at the beginning and end), it would start working again.


Update: Now after added /api/ to my .env file, it breaks other non-api routes. So I changed it back to API_PREFIX=api and I guess I'll just have to change my api/auth route to something else so it doesn't use the reserved api word in the url.

Yeah the prefix is now reserved for API routes as they're routed through a completely separate router instance to the other Laravel routes.

Confirmed. If using /api/ for API_PREFIX it will break. When using api as API_PREFIX it works. May be need to highlight somewhere? Some sample documentation on the net still using /api/ as the prefix.

Im using laravel 5.1 and i have same problem , after a hour searching i got the solution , as @LiangJianle mentioned ,
problem was in API_Domain
set it to empty in your .env ( don not forgot tu run artisan config:cache after changing your .env file ) or config/api.php , run php artisan api:routes to get all your routes and call

the route in localhost:8000/routename

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sogl picture Sogl  路  4Comments

pedrolari picture pedrolari  路  3Comments

adrian-fjellberg picture adrian-fjellberg  路  4Comments

pongz79 picture pongz79  路  4Comments

yaoshanliang picture yaoshanliang  路  4Comments