1

Access to XMLHttpRequest at 'http://localhost:8080/socket.io/?EIO=3&transport=polling&t=MgBuvgw' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

1 Answers1

1

Due to a security reasons browsers won't allow you to access other websites content until you specify with cors headers.

For more information on cors https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

Fix:

quick solution: in public/index.php add the following headers

header('Access-Control-Allow-Origin:  *');
header('Access-Control-Allow-Methods:  POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Headers:  Content-Type, X-Auth-Token, Origin, Authorization');

For better control and good practice use this package:

https://github.com/barryvdh/laravel-cors

Jagadesha NH
  • 2,529
  • 2
  • 23
  • 41
  • Hi, We used the command you shared but actually we faced the above issue only while connecting with web socket. Other than that we can be able to fetch the data. – Arun Pandian May 06 '19 at 07:45