Laravel 5 + AngularJS Cross Domain CORS

后端 未结 7 1566
暖寄归人
暖寄归人 2020-12-31 23:28

I have searched everywhere for an answer but nothing have worked so far. All the listed solutions on stack have not proven to be sufficient.

I get nothing in my lar

7条回答
  •  庸人自扰
    2020-12-31 23:41

    what i have done but not sure if that is the best solution but there are no cors with that one

    1.build the angular normally using ng build --prod

    2.move the content of angular/dist to laravel/public

    3.then use this simple code in laravel/routes/web.php

    Route::prefix('api')->group(function () {
        Route::get('/', function () {
        return view('welcome');
        });
    });
    Route::get('/{params?}', function () {
    //    return view('welcome');
        include_once '../public/index.html';
    })->where('params', '(.*)');
    

    now all requests comes to Laravel and if it can catch the request with a route this route will work otherwise it will pass it to angular

提交回复
热议问题