How to mount express.js sub-apps?

前端 未结 2 1823
被撕碎了的回忆
被撕碎了的回忆 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 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

提交回复
热议问题