开发者

Node.js as an application container

Apache and Node.js have something in common. The more I use Node.js, the more I like Node.js; similarly, more I use Apache, the more I like Node.js.

One good thing about Apache though, it can do a lot of things through the same port. PHP, Python, Perl, different apps, differ开发者_StackOverflow中文版ent paths, the whole magilla. Node.js doesn't do that, and it isn't supposed to but I would like to do something similar.

I would like to give it a list of URL-prefixes (or regexps ideally) and enough information to, if it receives a request matching a particular prefix, it passes off the request to a subordinate instance running a specified script (and it will start such an instance if it hasn't already, and close it down when doing so seems prudent). Basically, I want nodejs-proxy and cluster cooperating. With it, I could run several apps together on the same machine through port 80.

This seems pretty easy and very useful and I was about to just write it myself when it occurred to me, "This seems pretty easy and very useful -- probably someone has already written it!" Any suggestions?


Node.js doesn’t have any built-in ability to route requests to different applications, but frameworks like this are in development.

Nodejitsu’s Haibu comes to mind — it manages child processes for each application and uses node-http-proxy to route the requests.


You could take a look at http://expressjs.com which I describe as a 'sinatra for node'. It gives the whole URL/pattern based routing thing. You can couple this with https://github.com/visionmedia/express-resource to create a kinda RESTful style resource approach.


To me it sounds like you're looking for an event-based HTTP proxy (to replace Apache) - in that regard, nginx seem to be current king of the hill.


Use dokku (Docker based) which will spawn your apps and provide a reverse proxy via nginx. Containers are isolated, you have a choice of buildpacks and your deployments have 0 downtime all by pushing repos via git and auth via ssh.

You can follow this easy guide on DigitalOcean on how to deploy your Node.js apps or just watch the guide from the man himself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜