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.

2

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.