Node + now.js + Model-View-Control-Pattern [英] Node + now.js + Model-View-Control-Pattern

查看:79
本文介绍了Node + now.js + Model-View-Control-Pattern的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用基于MVC-Pattern(模板和PHP类)的论坛软件。
页面如下所示:domain.com/index.php?page=Test

I'm using a forum software which is based on MVC-Pattern (Templates and PHP-Classes). Pages look like this: domain.com/index.php?page=Test

我想在一个页面上设置聊天服务器(domain.com/index .php?page = Chat)与node和now.js.
现在我解决了一个问题:如何告诉服务器端代码聊天服务器必须在index.php工作?page = Chat
显然我不能做那样的事情:

I want to setup a chatserver on one page (domain.com/index.php?page=Chat) with node and now.js. Now I encouter a problem: How to tell the server side code that the chat server has to work at index.php?page=Chat Obviously I can't do something like that:

fs.readFile('index.php?page=Chat')

如何在这样的URL上设置节点服务器?
谢谢!

Any ideas how to setup a node server on URLs like that? Thanks!

推荐答案

我会更深入地了解node.js.由于节点 本身就是一个网络服务器,您必须先了解一下路由和服务器配置的工作原理。基本上,任何进入端口80的内容都由您的(可能的)Apache服务进行监听。 Apache查看URI,并决定运行应用程序中的哪个脚本启动运行代码的php进程并生成要发送给用户的网页。

I would dive a little deeper into node.js. As node is itself a webserver, you have to learn a little about how routing and server configuration work. Basically, anything coming in on port 80 is listened to by your (likely) Apache Service. Apache looks at the URI, and decides which script in your application to run kicks off a php processes that runs your code and generates a web page to be sent to the user.

所以当你看到:

domain.com/chat

vs

domain.com/index.php?page=Chat

这就是Apache说的,嘿,你让我把'/ chat'看作/index.php ?page = Chat,所以我将解开该脚本。

That's Apache saying, "hey, you configured me to read '/chat' as /index.php?page=Chat, so I'll fire that script off".

Node.js就像Apache和PHP一样。它处理请求并构建页面。因此,当请求进入时,你会让node.js和Apache踩到彼此的脚趾。要让两个应用程序在端口80上侦听,你必须使用类似的东西:

Node.js is like both Apache AND PHP balled up into one. It handles the requests and builds the pages. So you would have node.js and Apache stepping on each others toes when requests come in. To have both applications listening on port 80 you would have to user something like:

https://github.com/nodejitsu/node-http-proxy

此节点模块将未处理的服务器请求转发给Apache,这将允许您使用混合的nodejs / apache + php应用程序。

This node module forwards unhandled server requests to Apache, which would allow you to have mixed nodejs/apache+php application.

就模板而言,php和javascript模板无法混合,因为它们是在完全不同的语言上构建的。所以,你几乎没有运气。 Node有一个非常丰富的模板引擎列表。其中一些语法可能与您使用的语法几乎完全相同,因此移植起来很简单。

As far at the templating goes, php and javascript templates can't be intermingled as they're built on completely different languages. So, you're out of luck, almost. Node has a very rich templating engine list. Some of which are likely to have near identical syntax to whatever you're using, so it would be simple to port.

https://github.com/joyent/node/wiki/modules#wiki-templating

我希望这能回答你的问题。我仍然会像评论一样使用iFrame,将节点放在不同的端口上,并保持两个架构的清洁和分离。或者,使用聊天服务,不要费心设置一个完整的单独应用程序。除非你想学习,在这种情况下,要发疯。 :)

I hope this answers your question. I would still, as commented, use an iFrame, put node on a different port, and keep the two architectures clean and separate. Or, use a chat service and don't bother setting up a whole separate application. Unless you want to learn, in which case, go crazy. :)

这篇关于Node + now.js + Model-View-Control-Pattern的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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