RequireJS + NodeJS returning XMLHttpRequest cannot load 'http' No 'Access-Control-Allow-Origin' header

493 views Asked by At

Im trying to use JsSIP, but when I use the RequireJS to enable require in the client side CHROME returns:

XMLHttpRequest cannot load http://localhost/videochat/videonodejs/scripts/jssip. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

Its all in localhost, so what could be the origin problem? I do have the port number in my URL, could that be it?

2

There are 2 answers

2
Paul On BEST ANSWER

The jssip request is on port 80 the app is on port 3000. Those are not the same origin, per the same-origin policy.

0
ryan.l On

The server needs to specify the allowed origins in the Access-Control-Allow-Origin header. Often times this value is set to '*' so it captures all client origins, or it is set to a white-list of allowed origins. This is defined in the server code and is required for ay API that handles cross-domain requests.

Look into CORS configuration for your application if adding the Access-Control-Allow-Origin header doesn't work. If it doesn't work, you may eventually need to look into "pre-flight" requests. They are an initial request sent to the server to determine server support for the upcoming request, and it's HTTP method is OPTIONS. So, if you handle the server code, you will need to add 'OPTIONS' to the list of allowed methods, so you can handle that pre-flight request and thereby inform the browser that it should continue and send the real request to the server..... I believe you can disable this behavior in chrome by launching with a command line flag (which i think is --disable-web-security). Hope this is able to help you some.