0

I built a web app with the Dart Editor and everything was working great when testing in Dartium. I wanted to test it out on a hosting site, so I ran Pub Build from the tools menu. It looks like it created the build folder and put everything in there, including a .js file from the .dart file I had. When I ran the .html file that I normally do, nothing happened. I looked at the source code and it was still pointing to the .dart file, so I changed that to the .js file. Still didn't see the expected results.

This is my first time trying to run a dart application outside of the Dart VM. Am I missing a step somewhere? Not really finding any documentation on this either.

DuckyDisciple
  • 105
  • 1
  • 1
  • 11
  • What happens when you launch the app from DartEditor and then copy the URL to Chrome or Firefox? – Günter Zöchbauer Apr 01 '15 at 04:25
  • Almost everything works when I run it in Chrome. The DOMs that get changed on page load are working. Event listeners are working. The only thing that doesn't work is an error is returned when I try to use the GetString method for a site external to my project. – DuckyDisciple Apr 02 '15 at 03:26
  • Do you get any errors in the browser console when you run it from the build directory? – Günter Zöchbauer Apr 02 '15 at 04:12
  • Ahh...didn't think to check there. It says "XMLHttpRequest cannot load _file_. Cross origin requests are only supported for protocol schemes ..." The file that it is trying to load is just an html file that gets loaded into the page when the page loads. – DuckyDisciple Apr 02 '15 at 11:10

1 Answers1

0

If you try to fetch resources from another server than the one your page was loaded from, this server needs to return CORS headers otherwise your browser refuses to fetch form this other server. It depends on your server how this can be configured or added.

See for example
- How do you add CORS headers in Redstone interceptor?
- CORS with Dart, how do I get it to work?

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • The problem you describe makes sense since I am trying to pull data from an API on a different site, but I'm not sure I understand the resolution. It looks like the client sends a request to the server, the server adds the headers, and then does that request continue on to the external site before the response comes back to the client? – DuckyDisciple Apr 03 '15 at 15:57
  • Honestly I don't understand why/how this improves security, but if JavaScript fetches resources from a different site than the page origin, the server needs to allow it. It responds with CORS headers which are cached by the browser. The next time the browser doesn't even try to sends the request the CORS headers don't allow the page origin URL. If you make a post request, an extra request is made before the actual post request (preflight request), just to check the CORS headers. If they don't allow your page origin, the post request itself isn't made at all. There is more to CORS. – Günter Zöchbauer Apr 03 '15 at 16:06
  • ... but not my area of expertise. – Günter Zöchbauer Apr 03 '15 at 16:06