How to debug client side dart code in Dart editor without CORS

送分小仙女□ 提交于 2019-12-24 10:44:28

问题


I have a server / client project, both written in dart. Now my server starts on port 1337 and when I run my client with the Run in dartium, my static files are served on port 3030 which allows me to debug my client code in the Dart editor.

The problem is that this causes CORS when using AJAX calls. I have properly setup my server to accept other origins (with Access-Control-Allow-Origin) but, for example, cookies aren't sent along.

Now I'm wondering: is there a way to serve my files with my server (running on 1337) and still have the possibility to debug the client side code in the dart editor?


回答1:


My understanding is that you can debug, but the real problem is that you don't get the expected data back from the server due to missing cookies.

Standard CORS requests do not send or set any cookies by default.

In order to include cookies as a part of the request, besides setting up the server, you need to specify withCredentials property, e.g.:

HttpRequest.getString(url, withCredentials:true)...

You will also need to setup server to provide Access-Control-Allow-Credentials header.

EDIT: it seems that additional issue is that you don't want to have 2 servers, each serving different part of app.

In that case, you can configure DartEditor to launch the URL, instead of files. Go to Run > Manage Launches and add create a new Dartium or Dart2JS launch with specified URL and source directory.

Another option is to select Run > Remote Connection and attach to a running instance of browser or Dart VM.

Caveat: I haven't tried these options, so I can't tell how stable they are.



来源:https://stackoverflow.com/questions/16939328/how-to-debug-client-side-dart-code-in-dart-editor-without-cors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!