开发者

Multiple apps from the same server

开发者 https://www.devze.com 2023-03-22 12:34 出处:网络
I am used to deploying Tomcat servers (and other J2EE containers) and they have a directory where I can drop WAR files.Say there\'s file called xyz.war, then when I access do a GET against that server

I am used to deploying Tomcat servers (and other J2EE containers) and they have a directory where I can drop WAR files. Say there's file called xyz.war, then when I access do a GET against that server for any path starting with /xyz, the request is passed to the application in that war file.

Now I want to do an analogous thing under node.js . I have several application and I want them to run in different namespaces (both from a JavaScr开发者_运维技巧ipt and a URL point of view). Is this even possible?


In the java world because the jvm is rather heavyweight we tend to deploy multiple applications in the same jvm process. Node.js is much more lightweight which allows running each node app in a separate process. I think this has several advantages such per process isolation (for example what if a buggy app uses up all the heap) and the ability to restart a node app without affecting the other apps running on the same server.

To have them running off the same port you would then put something like nginx or node-http-proxy in front of them. If you need new apps to be detected and started automatically you could write a script that monitors your 'app directory' and generates some new configuration for nginx (for example detect a new directory 'xyz', map it under /xyz in nginx and start the node app in that directory).


It's possible but not easy. You'll have to build your own framework to do it. One of the things that a J2EE container provides is isolation using separate classloaders. That kind of isolation will be hard to build. But creating some sort of plugin architecture where node.js reads files in separate directories shouldn't be too difficult if you ignore isolation security.

0

精彩评论

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

关注公众号