如何组织混合HTTP服务器+ Web客户端Dart项目文件? [英] How to organize mixed HTTP server + web client Dart project files?

查看:169
本文介绍了如何组织混合HTTP服务器+ Web客户端Dart项目文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划创建一个纯Dart应用程序,其中HTTP服务器和Web客户端都用Dart编写。来自Java和Eclipse的最终将是我可以打开整个项目层次结构在Dart编辑器,并能够运行服务器的客户端文件和调试应用程序的两侧(服务器端与DartVM和客户端与Dartium )。



我已经启动了Dart编辑器,在创建了一个简单的命令行应用程序作为服务器端的基础之后,我困惑了项目布局。 p>

直接服务器端代码文件(web服务器boostrap类,处理程序和过滤器类)肯定会进入项目bin /文件夹。



当服务器必须访问客户端应用程序文件(.dart文件,静态页面源代码,等等),以便为浏览器提供服务。最简单的解决方案是在服务器项目中创建一个web文件夹,并将客户端web文件放在那里,但是这种方式(据我所知),服务器端依赖项被继承到客户端,因为我们仍然在同一个pubspec范围内。我不想这样。



我想在项目lib /文件夹中创建一个客户端库,并把web文件放在那里,但我不知道好的做法是以将完整的Web应用程序放入其中。我想我必须把HTML和其他客户端静态文件放入lib的资产/子文件夹。我很担心我以这种方式失去了来自IDE的Web应用程序帮助。



我还可以做的是将客户端放入单独的项目,组织它像一个Dart webapp项目,它有自己的pubspec.yaml,然后使这是服务器应用程序的依赖。我不知道这样的方式服务器可以访问其他项目中的Web文件服务。这可能是最好的方式,因为它提供了一个干净的客户端和服务器文件的分离。



有人能告诉我什么是正确的方法吗? / p>




有些解释。
说我要使用单独的项目方法,因为其他人已经在答案中建议,但我仍然喜欢运行服务器,能够在开发阶段服务客户端没有任何花哨的黑客。服务器必须访问其他项目中的客户端文件。没关系,如果它的Javascript或Dart,静态文件还有。在开发期间我希望提供dart文件,因为Dartium加速了开发,显着地具有直接的Dart运行能力。



使用Java和Maven可以使客户端包运行服务器和i的依赖可以简单地从类路径提供客户端文件。 Dart是否支持访问pub依赖的内部文件,类似的方式,或者唯一的方法是将所有东西放在客户端的资产文件夹中,或者使用相对路径hack?

解决方案

这是正在进行的工作:





为了提高开发体验,您可以使用符号链接作为解决方法,以便在服务器包的目录中提供客户端文件。



我建议您通过 http://www.dartbug.com/new 创建功能请求,以便更好地支持。


I'm planning to create a pure Dart application where both the HTTP server and the web client side is written in Dart. Coming from Java and Eclipse the ultimate would be that i can open the whole project hierarchy in Dart Editor and be able to run the server which serves the client files and debug both sides of the app (server side with the DartVM and client side with Dartium).

I've fired up Dart Editor and after creating a simple Command-line application as the basis for the server side i got confused with the project layout.

The direct server side code files (web server boostrap class, handler and filter classes) are definietly going into the projects bin/ folder. Server side dependencies are going into the project's pubspec.yaml file.

The problem arrises when the server have to access the client application files (.dart files, static page source, etc.) in order to serve them to the browser. The easiest solution would be to create a web folder inside the server project and put client web files there, but this way (as far as i understood) server side dependencies are inherited into the client because we are still in the same pubspec scope. I don't want this.

I thought about creating a client library in the projects lib/ folder and put web files there but i don't know how good practice is to put a complete web application into there. I guess i have to put HTML and other client static files into the asset/ subfolder of the lib. I'm affraid that i'm loosing web application assist from the IDE this way.

What i might also be able to do is to put the client into a separate project, organize it like a Dart webapp project with it's very own pubspec.yaml and then make this the dependency of the server application somehow. I don't know if this way the server could access web files in the other project for serving. Probably this is the best way of doing it because it provides a clean separation of the client and server files.

Can somebody enlighten me what's the correct way of doing this?


Some more explanation. Say i'm going with the separate project approach as others already suggesting in the answers but i still like to run the server which is able to serve the client in the development phase without any fancy hack. The server has to access the client files in the other project. It doesn't matter if its Javascript or Dart, the static files are there anyway. And during development i wish to serve the dart files since Dartium speeds up development with it's direct Dart running capability significantly.

With Java and Maven i can make the client package a runtime dependency of the server and i can simply serve the client files from the classpath. Does Dart support accessing a pub dependency's internal files the similar way or the only way for this is to put everything into the asset folder of the client or going with the relative path hack?

解决方案

This is work in progress:

To improve the development experience you may use a symlink as a workaround so that you have the client files available in a directory of the server package.

I suggest creating a feature request at http://www.dartbug.com/new for better support.

这篇关于如何组织混合HTTP服务器+ Web客户端Dart项目文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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