Web 应用程序的前端架构
我必须编写一个新的 Web 应用程序,目前正在决定架构的过程中,我知道我希望能够做几件事:
- 所有机器必须是对称的,即:商品机器没有自定义构建服务器(aws) )
- 我想要一个与 UI 分离的 ReST API,因为我已经拥有该 API 的三个客户端:移动应用程序、网站和来自第三家公司的服务器,等待产品构建,
- 它需要能够水平扩展(一个但是重复1)
- 易于维护:没有时间学习新语言,更多可用候选人但愿意采用新技术
这里是我提出的基本架构:
nginx+nodejs+expressjs+YUI 的前端组合, api:nginx+tomcat+spring 框架堆栈(rest+Security+core+aop)
前端将使用 oAuth 2.0 与 api 进行对话
对于 api 来说没什么令人兴奋的,我以前做过,我知道它可以工作并且工作得很好会喜欢添加一些 scala 风味,但我没有时间。
我主要关心的是前端:nodejs 非常令人兴奋,我已经玩了一段时间也喜欢它在 JS 中的事实,但我担心导航+模板+会话(仅用于身份验证:无状态,无状态,无状态)+日志记录+调试它,如果它工作得很好,但它不是一个成熟的开发环境......
这里有人开发了带有堆栈或其子集的完整前端吗?还有其他建议可供选择吗?
谢谢你们。
I have to write a new web application and currently am in the process of deciding on the architecture , there are several things i know i want to be able to do :
- All machine must be symmetric , i.e. : commodity machines no custom build servers (aws)
- I want a ReST API that is seperated from the UI as i allready have three clients for the API : mobile applications , the web site and a server from a 3rd company waiting for the product to be build
- it needs to able to scale horizontal (a but of a repeat of 1)
- Easy to maintain : no time to learn new languages , more available candidates but willing to adopt new technologies
here is the basic architecture i've come up with :
frontend combining of nginx+nodejs+expressjs+YUI ,
api : nginx+tomcat+spring framework stack (rest+Security+core+aop)
the frontend will talk to the api with oAuth 2.0
nothing exciting about the api i've done it before , i know it works and works well would have loved to put some scala flavour but i don't have the time .
my main concern is the frontend : nodejs is insanely exciting and i've been playing around for some time also love the fact it's in JS , but i'm afraid about navigation+templating+sessions (for authentication only : stateless,stateless,stateless)+logging+debugging of it , if it works it works well but it's not a mature enviourment to develop in .....
anyone here developed a full frontend with stack or subsets of it ? any other suggestions to choose from ?
thanks guys .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
导航?不确定你在这里的意思。使用超链接。 AFAIK 中没有像 Rails 的
form_for()
类型帮助器那样的节点,但这些对我来说从来没有那么有趣。如果你想要类似 Rails 风格的前/后过滤器,比如需要登录用户,connect 就可以做到这一点。这将为任何以
/app
开头的路径调用requireUser
。在requireUser
中,您可以确保req.session.user
存在(并且可能具有适当的授权)。如果是这样,您调用next()
并执行负责实际生成响应的中间件。如果用户未登录或未授权,您可以生成 30X 重定向响应,并且不调用next()
。完毕。 express.js 指南中有一个与此完全相同的很好的示例。搜索loadUser
。这个设计真的很优雅,恕我直言。模板化?呃,node.js 拥有与任何其他平台一样好甚至更好的模板选项。尝试 jade 或其他十几种。您可以在服务器和浏览器中使用相同的模板,这是一个很好的胜利。观看 这段 Dav Glass 在服务器端使用 YUI 小部件的视频node.js 因为你喜欢 YUI。
会议? 连接会话。味道好极了。填充量较少。有什么问题吗?
记录? Winston 为我工作。我认为还有更精美的图书馆。
调试? node-inspector 为node.js(恕我直言)提供了最好的调试支持。它使用 chrome 的检查器进行调试,并且与调试客户端 javascript 一样出色。通过 jasbin 运行时,我还可以调试服务器端单元测试。
这是哪些公司正在使用节点的答案生产中的 .js。
navigation? Not sure what you mean here. Use hyperlinks. AFAIK there's nothing in node like Rails'
form_for()
type helpers, but those were never that interesting to me. If you want something like Rails style before/after filters, say for requiring a logged in user, connect does this great.That will call
requireUser
for any path starting with/app
. InsiderequireUser
you can make surereq.session.user
is there (and maybe has proper authorization). If so, you callnext()
and the middleware responsible for actually generating the response is executed. If the user isn't logged in or is not authorized, you can generate a 30X redirect response and don't callnext()
. Done. There's a great example exactly like this in the express.js guide. Search forloadUser
. This design is really elegant, IMHO.templating? Uh, node.js has as good or better templating options than any other platform. Try jade or any of a dozen others. You can use the same templates on the server and in the browser, which is a nice win. Check out this video of Dav Glass using YUI widgets on the server side in node.js since you like YUI.
sessions? Connect sessions. Taste great. Less filling. What's the problem?
logging? Winston works for me. There are also fancier libraries as well I think.
debugging? node-inspector gives node.js (IMHO) the best debugging support available. It debugs with chrome's inspector and is every bit as awesome as debugging client side javascript. I can also debug server side unit tests when running via jasbin.
Here's an answer to what companies are using node.js in production.
因此,如果您在测试时遇到问题,那么您只是误解了 Node.js 和 Express 的某些功能。例如,您可以使用类似这样的内容进行测试:
然后您需要删除 controlles.js 中所需的所有文件的缓存:
因此,现在您的控制器将在请求通过时立即更新到当前版本。
要了解 Nodejs require 如何工作,只需尝试以下操作:
require.js
main.js
So if you got problem with testing then you just misunderstand some features of Node.js and express. For example you can use something like this for testing:
Then you need to drop cache with all files required in your controlles.js:
So now your controller will updated instantly to current version when request pass.
To understand how does nodejs require work just try this:
require.js
main.js