Question

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

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')

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

Was it helpful?

Solution

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.

So when you see:

domain.com/chat

vs

domain.com/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 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

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

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

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. :)

OTHER TIPS

you can run node server at port say 8080 and can include client side js as normal javascript in any of the view file it will work

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top