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

How to do if I have two route types: /* and api/* in my Laravel Project ? #446

Open
jornatf opened this issue May 15, 2023 · 2 comments
Open

Comments

@jornatf
Copy link

jornatf commented May 15, 2023

How to do if I have two route types: /* and api/* in my Laravel Project ?

I have two routes types in my Laravel Project: /* for user access dashboard and api/* for api access.

If I do like this:

    "functions": {
        "api/index.php": {
            "runtime": "vercel-php@0.5.2"
        }
    },
    "routes": [
        {
            "src": "/api/(.*)",
            "dest": "/api/index.php"
        }
    ],

The url for /api/* is /api/api/*.

How fix it ?

Thx.

Jordan

@ronei-kunkel
Copy link

I found this on stackoverflow:
https://stackoverflow.com/questions/70534889/vercel-api-conflict-with-laravel-api

I don't try this, but maybe work for you

@ronei-kunkel
Copy link

@jornatf

I found other way to avoid this behavior, but it make an inconsistency between local and server environment:

condition:

  • your api need to be versioned, like v1, v2, etc.

inconsistencies:

note:

the only behavior that you can change is:

To avoid this you can create one page that supply both the application access like an form to login/register and one button to reference the api documentation

changes:

RouterServiceProvider

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

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

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

api.php

Route::prefix('v1')->group(function () {
    // all your routes need to be declare here
});

Route::prefix('v2')->group(function () {
    // or here to access the v2 of your api
});

// or in both if you want segregate the resources or any other reason

web.php

// i didnt any changes

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

2 participants