I am trying to deploy my Laravel app on Vercel.
Here is the RouteServiceProvider.php code:
...
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('apis')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
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'));
});
}
...
The code in my api.php:
Route::get('/', function () {
return 'this is an API';
});
Route::get('/person', function () {
$person = [
'first_name' => 'Sean',
'last_name' => 'Pooley',
];
return $person;
});
At local env, localhost/api and localhost/api/person, works fine but when I deploy it on Vercel, the api myapp/api/person doesn't work but myapp/apis/person, myapp/apis/, myapp/api display what I want.
I suspect that the route is always refer to Vercel instead of Laravel route because there is one directory api at the root, so whenever calling for api it will direct to that folder. So is there anyway to overcome this issue? Or only can use apis as the prefix at the Laravel?
apifolder is at the root directory, which have aindex.phpfile to tell vercel to forward request to normalindex.php(at public/index.php). Why would you ask that? (curious