简体   繁体   English

如何在没有CORS的Dart编辑器中调试客户端dart代码

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

I have a server / client project, both written in dart. 我有一个服务器/客户端项目,都是用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. 现在我的服务器从端口1337开始,当我使用Run in dartium运行我的客户端时,我的静态文件在端口3030 ,这允许我在Dart编辑器中调试我的客户端代码。

The problem is that this causes CORS when using AJAX calls. 问题是这在使用AJAX调用时会导致CORS I have properly setup my server to accept other origins (with Access-Control-Allow-Origin ) but, for example, cookies aren't sent along. 我已正确设置我的服务器以接受其他来源(使用Access-Control-Allow-Origin ),但是,例如,cookie不会被发送。

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? 现在我想知道:有没有办法用我的服务器(在1337运行)提供我的文件,并且还有可能在dart编辑器中调试客户端代码?

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. 我的理解是你可以调试,但真正的问题是由于缺少cookie而你没有从服务器获得预期的数据。

Standard CORS requests do not send or set any cookies by default. 标准CORS请求默认不发送或设置任何cookie。

In order to include cookies as a part of the request, besides setting up the server, you need to specify withCredentials property, eg: 为了将cookie作为请求的一部分包含在内,除了设置服务器之外,还需要指定withCredentials属性,例如:

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

You will also need to setup server to provide Access-Control-Allow-Credentials header. 您还需要设置服务器以提供Access-Control-Allow-Credentials标头。

EDIT: it seems that additional issue is that you don't want to have 2 servers, each serving different part of app. 编辑:似乎另外一个问题是你不想拥有2台服务器,每台服务器都服务于应用程序的不同部分。

In that case, you can configure DartEditor to launch the URL, instead of files. 在这种情况下,您可以配置DartEditor以启动URL而不是文件。 Go to Run > Manage Launches and add create a new Dartium or Dart2JS launch with specified URL and source directory. 转到Run > Manage Launches然后添加使用指定的URL和源目录创建新的Dartium或Dart2JS启动。

Another option is to select Run > Remote Connection and attach to a running instance of browser or Dart VM. 另一个选项是选择Run > Remote Connection并附加到正在运行的浏览器或Dart VM实例。

Caveat: I haven't tried these options, so I can't tell how stable they are . 警告:我没有尝试过这些选项,所以我不知道它们 有多稳定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM