- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好我正在尝试创建一个 Web 应用程序,您可以在其中通过 Web 浏览器访问系统上的文件。 Web 应用程序结构如下所示:
指挥官
cmdr
packages
lib
cmdr.dart
gui
packages
web
assets
css
console.dart
editor.dart
client.dart
explorer.dart
index.html
cmdr.dart
是服务器,我启动
http_server
主持
index.html
在那里。指数拉动
client.dart
文件作为脚本。
editor.dart
,
console.dart
和
explorer.dart
文件都是客户端文件的一部分。
http_server
主持
index.html
,它不访问客户端文件。除了 CSS 文件之外,大多数依赖项都不会被提取。此外,我认为也许编译成 javascript 可以解决这个问题,因为它将所有代码合并到一个文件中。然而,同样的问题存在于将 HTML 放在一起但没有创建任何客户端组件的情况下。
// Setting up Virtual Directory
VirtualDirectory virDir;
void directoryHandler(dir, request) {
var indexUri = new Uri.file(dir.path).resolve('index.html');
virDir.serveFile(new File(indexUri.toFilePath()), request);
}
void main(List<String> args) {
// Set default dir as current working directory.
Directory dir = Directory.current;
// Creating Virtual Directory
virDir = new VirtualDirectory(Platform.script.resolve('/Users/donghuynh/git/commander/gui/web').toFilePath())
..allowDirectoryListing = true
..directoryHandler = directoryHandler
..followLinks = true;
// Set up logging.
log = new Logger('server');
Logger.root.onRecord.listen(new SyncFileLoggingHandler("server.log"));
// Create an args parser to override the workspace directory if one is supplied.
var parser = new ArgParser();
parser.addOption('directory', abbr: 'd', defaultsTo: Directory.current.toString(), callback: (directory) {
dir = new Directory(directory);
});
parser.parse(args);
// Initialize the DirectoryWatcher.
watcher = new DirectoryWatcher(dir.path);
// Set up an HTTP webserver and listen for standard page requests or upgraded
// [WebSocket] requests.
HttpServer.bind(InternetAddress.ANY_IP_V4, 8080).then((HttpServer server) {
log.info("HttpServer listening on port:${server.port}...");
server.listen((HttpRequest request) {
// WebSocket requests are considered "upgraded" HTTP requests.
if (WebSocketTransformer.isUpgradeRequest(request)) {
log.info("Upgraded ${request.method} request for: ${request.uri.path}");
WebSocketTransformer.upgrade(request).then((WebSocket ws) {
handleWebSocket(ws, dir);
});
} else {
log.info("Regular ${request.method} request for: ${request.uri.path}");
// TODO: serve regular HTTP requests such as GET pages, etc.
virDir.serveRequest(request);
}
});
});
}
http://localhost:8080/packages/bootjack/css/bootstrap.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/packages/ace/src/js/ext-language_tools.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/packages/ace/src/js/ace.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/packages/browser/dart.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/packages/bootjack/css/bootstrap.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
最佳答案
据我记得,您需要向 VirtualDirectory
传递一个附加参数。遵循符号链接(symbolic link)。
无论如何,您都不应直接提供 Dart 源代码,而应使用 pub build
的输出。 (至少用于生产)。对于开发,将请求转发到正在运行的 pub serve
instance 可能是更好的方式,也是官方建议的方式。
关于Dart http_server 服务 index.html 但不拉依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27517430/
我正在尝试完成以下教程(参见此处:https://www.alanzucconi.com/2015/11/01/interactive-graphs-in-the-browser/)。但是,当我尝试导
我一直在用dart:route api 用于提供静态文件,但我注意到有一个名为 http_server 的核心库包含 dart:io 的辅助类和函数HttpServer . 我特别感兴趣的是类(cla
您好我正在尝试创建一个 Web 应用程序,您可以在其中通过 Web 浏览器访问系统上的文件。 Web 应用程序结构如下所示: 指挥官 cmdr packages lib
我创建了 .condarc 文件设置 http_servers 如前所述 here , , 但是当我调用 conda info它给出了以下输出: C:\Users\[...]\AppData\Loca
我是一名优秀的程序员,十分优秀!