WebStorm 如何运行 Dart 网络应用程序

How WebStorm runs Dart web apps

当 运行在 WebStorm 中使用 Dart 网络应用程序时,"Pub Serve" 选项卡上的 ?底部的窗格报告以下内容(--port 不同于 运行 运行):

/home/tom/dart-sdk/bin/pub serve web --port=46247
Loading source assets...
Loading polymer transformers...
Serving polymer_and_dart web on http://localhost:46247

但是,可以在 http://localhost:63342.

访问该应用程序

然而,当我从命令行 运行 pub serve 时,可以在 localhost:46247:

访问该应用程序
/home/tom/dart-sdk/bin/pub serve web --port=46247

有人可以解释一下 WebStorm 在指定端口做什么,如果它不是为应用程序提供服务的话?

顺便说一句,我在开发中只使用 Dartium。

WebStorm 有一个集成的代理,它在自己的端口上侦听并转发到 pub serve 正在侦听的端口。

pub serve 将在 Dart 2 中删除。

目前 4/2018 pub run build_runner serve 没有与 IntelliJ 集成,但正在进行中。

Webstorm 2018.1 似乎做了一些与代理有点不同的事情。 Webstorm 在调试端口运行一个 Web 服务器,当它收到 GET http://localhost:{{debugPort}}/web/web/{{targetPage}} 时,它将以 302 重定向响应。重定向的位置 header 将引用目标页面在 Dart 网络应用程序中的实际位置。

如果您在开发过程中偶然需要以编程方式获取随机端口,您可以在 Webstorm 调试器设置中启用 "Allow unsigned requests",然后编写一些脚手架代码来获取位置 header。