Web 应用程序的前端架构

发布于 2024-11-29 03:33:50 字数 667 浏览 0 评论 0原文

我必须编写一个新的 Web 应用程序,目前正在决定架构的过程中,我知道我希望能够做几件事:

  1. 所有机器必须是对称的,即:商品机器没有自定义构建服务器(aws) )
  2. 我想要一个与 UI 分离的 ReST API,因为我已经拥有该 API 的三个客户端:移动应用程序、网站和来自第三家公司的服务器,等待产品构建,
  3. 它需要能够水平扩展(一个但是重复1)
  4. 易于维护:没有时间学习新语言,更多可用候选人但愿意采用新技术

这里是我提出的基本架构:

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 :

  1. All machine must be symmetric , i.e. : commodity machines no custom build servers (aws)
  2. 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
  3. it needs to able to scale horizontal (a but of a repeat of 1)
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

霓裳挽歌倾城醉 2024-12-06 03:33:50

但我担心导航+模板+会话(对于
仅身份验证:无状态,无状态,无状态)+日志记录+调试
其中

导航?不确定你在这里的意思。使用超链接。 AFAIK 中没有像 Rails 的 form_for() 类型帮助器那样的节点,但这些对我来说从来没有那么有趣。如果你想要类似 Rails 风格的前/后过滤器,比如需要登录用户,connect 就可以做到这一点。

app.all('/app/*', requireUser)

这将为任何以 /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

but i'm afraid about navigation+templating+sessions (for
authentication only : stateless,stateless,stateless)+logging+debugging
of it

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.

app.all('/app/*', requireUser)

That will call requireUser for any path starting with /app. Inside requireUser you can make sure req.session.user is there (and maybe has proper authorization). If so, you call next() 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 call next(). Done. There's a great example exactly like this in the express.js guide. Search for loadUser. 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.

怎会甘心 2024-12-06 03:33:50

因此,如果您在测试时遇到问题,那么您只是误解了 Node.js 和 Express 的某些功能。例如,您可以使用类似这样的内容进行测试:

app.get('/route', function(req,res,next) {
    require('./controllers.js').method(req,res,next)
});

然后您需要删除 controlles.js 中所需的所有文件的缓存:

if (require.cache[__filename])
{
  var del = false;
  for ( i in require.cache)
  {
    if (i == __filename)
    {
      del = true;
    }
    if (del)
    {
      delete require.cache[i];
    }
  }
}

因此,现在您的控制器将在请求通过时立即更新到当前版本。

要了解 Nodejs require 如何工作,只需尝试以下操作:

require.js

module.exports = {};

ma​​in.js

var x = require('./require.js');
x.tell = true;
var y = require('./require.js');
y.tell = false;

console.log(require('./require.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:

app.get('/route', function(req,res,next) {
    require('./controllers.js').method(req,res,next)
});

Then you need to drop cache with all files required in your controlles.js:

if (require.cache[__filename])
{
  var del = false;
  for ( i in require.cache)
  {
    if (i == __filename)
    {
      del = true;
    }
    if (del)
    {
      delete require.cache[i];
    }
  }
}

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

module.exports = {};

main.js

var x = require('./require.js');
x.tell = true;
var y = require('./require.js');
y.tell = false;

console.log(require('./require.js'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文