How to mount express.js sub-apps?

前端 未结 2 1824
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 00:40

I have several apps that I\'m trying to merge into a single \"suite\": 2 apps are standalone, one is simply an auth layer (using everyauth for FB Connect). I want to set it

相关标签:
2条回答
  • 2020-11-29 00:51

    app.use(uri, instanceOfExpressServer)

    Just make sure you don't call .listen on it.

    The alternative is to use require("cluster") and invoke all your apps in a single master so that they share the same port. Then just get the routing to "just work"

    0 讨论(0)
  • 2020-11-29 01:00

    Not sure if this helps you but I was looking to prefix my API routes. What I did was that when I initialized the router, I added the mount path. So my configuration looks like this

    //Default configuration
    app.configure(function(){
        app.use(express.compress());
        app.use(express.logger('dev'));
        app.set('json spaces',0);
        app.use(express.limit('2mb'));
        app.use(express.bodyParser());
        app.use('/api', app.router);
        app.use(function(err, req, res, callback){
            res.json(err.code, {});
        });
    });
    

    Notice the '/api' when calling the router

    0 讨论(0)
提交回复
热议问题