Cors error at angle 6

Asked

Viewed 481 times

-1

Guys I’m having this mistake in a project:

Failed to load http://127.0.0.1:8000/hqi/pages: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:4200' is therefore not allowed access. 

And I can not solve, I followed some examples that taught to create a proxy file:

const proxy = [
{
   context: '/hqi',
   target: 'http://localhost:8000'
}];
module.exports = proxy;

however, it did not result the error persists, someone could help me?

  • you have to set up Cors in your backend

  • What are you wearing in the back-end?

2 answers

3


Add the following header to your back-end response.

httpResponse.setHeader("Access-Control-Allow-Origin", "*");

  • I’ll tell you where you can tell me?

  • Find the object that is used as a response to requests

  • according to the documentation that you pass me would be this Route::get('home', Function() { Return Response('Hello World', 200) ->header('Content-Type', 'text/Plain'); }); but work with routes like this Route::Resource('users', 'Usercontroller'); so I don’t know where that would fit in

  • add the header I mentioned in the answer in ->header('...')

  • Now yes I understood what was missing to understand was where I would put this, and it would be in the controller, I appreciate the tip

2

Probably the problem is in your backend, which language are you using ? You need to set the header: 'Access-Control-Allow-Origin' with the value '*' in your backend, it varies from language to language, put here the code of your backend so we can have an idea.

  • back end is php with Laravel and the front is angular

  • can post the backend code where you put Cors here ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.