I’m developing a VueJS app separated from a Laravel Backend, and I’m facing the Cors problem. I know what the problem is and I tried the following packages to solve it:
I followed the instructions carefully. I am sure I did not make any mistake when installing the packages, and I have tried them many times to ensure that no error was made. However, none of those packages worked completely. They worked well with
GET requests, but not with
OPTIONS. So, I implemented this simple Middleware:
* Handle an incoming request.
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
public function handle($request, Closure $next)
header('Access-Control-Allow-Headers: Origin, Content-Type, Authorization, X-Auth-Token, X-Requested-With');
header('Access-Control-Allow-Methods: POST, GET, PUT, PATCH, DELETE, OPTIONS');
This works perfectly if I run
php artisan serve on port 8000, and then set
window.axios.defaults.baseURL = 'http://127.0.0.1:8000/api'. However, this custom middleware do not work if I set
window.axios.defaults.baseURL = 'http://laravel-todo-vue.test/api', which is where my Laravel app is served by
I’d like make requests to
http://laravel-todo-vue.test because otherwise I have to change
axios.defaults.baseURL everytime that
php artisan serve uses another port when port 8000 is busy.
Any help is appreciated.
from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/2RpY99x