如何在没有CORS的Dart编辑器中调试客户端dart代码 [英] How to debug client side dart code in Dart editor without CORS

查看:334
本文介绍了如何在没有CORS的Dart编辑器中调试客户端dart代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务器/客户端项目,都是用dart写的。现在我的服务器在端口 1337 上启动,当我使用在dartium中运行运行我的客户端时,我的静态文件在端口 3030 ,这允许我在Dart编辑器中调试我的客户端代码。

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.

问题是, CORS 使用 AJAX 调用。我已经正确设置我的服务器接受其他来源(访问控制允许原点),但是,例如,cookies不随之发送。

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.

现在我想知道:有没有办法用我的服务器(在 1337 上运行)提供我的文件,在调试dart编辑器中的客户端代码?

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?

推荐答案

我的理解是你可以调试,但真正的问题是,

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.

标准CORS请求默认不发送或设置任何Cookie。

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

为了将Cookie作为请求的一部分包含在内,除了设置服务器之外,还需要指定 withCredentials 属性,例如:

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)...

您还需要设置服务器以提供 Access-Control-Allow-Credentials 头。

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

编辑:似乎额外的问题是,你不想有两个服务器,每个服务不同的应用程序的部分。

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

在这种情况下,你可以配置DartEditor以启动URL,而不是文件。转到运行>管理启动并添加创建新的Dartium或Dart2JS启动时指定的URL和源目录。

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.

另一个选项是选择运行>远程连接并附加到正在运行的浏览器实例或Dart VM。

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.

这篇关于如何在没有CORS的Dart编辑器中调试客户端dart代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆