1

I have a front-end running on Nuxt and Laravel as a back-end service. When I generate the signedURL using the Laravel's API middleware - the path includes "api" in the URL, resulting into a page not found exception on the Nuxt side

So, here are the steps to better understand what's happening:

  1. User clicks a button in Nuxt application and sends the ajax request to the Laravel API
  2. API Controller generates the signedURL

$signedUrl = URL::signedRoute('register', ['email' => $this->request->email, 'group_id' => $this->request->group_id], null, false);

  1. Generated URL includes the "api" in the path, which of course, cannot be accessed http://localhost:3000/api/register?email=ss%40gmail.com&group_id=2&signature=ce4fba05bf5ccae6ea20a6043a47ca11de603238214deda7202d19f2989272cb

Is there a way to get rid of the /api/ from the generated URL? I've tried setting 4th param (absolute) in the method signedRoute to false, but it doesn't help.

George Sharvadze
  • 560
  • 9
  • 25
  • Can you share your router for the `'register'` route ? – Christophe Hubert May 02 '20 at 12:09
  • Sue, here it is, under routes/api `Route::get('register', 'RegisterController@register')->name('register'); Route::post('register', 'Auth\RegisterController@register');` – George Sharvadze May 02 '20 at 12:46
  • The api default routes have prefix 'api' so when you generate the signed URL, you are requesting the route `register`, therefore the generated URL will be `www.mydomain.com/api/register?...` – Christophe Hubert May 02 '20 at 12:54

1 Answers1

0

The default api routes have prefix 'api' as seen in your RouterProvider:

    protected function mapApiRoutes()
    {
        Route::prefix('api')
               ...;
    }

When you generate the signed URL, for your route 'register' which is using the prefix api , the generated URL will be as expected: www.mydomain.com/api/register?...

Christophe Hubert
  • 2,833
  • 1
  • 12
  • 25