Is it possible to set a base URL for NodeJS app?

前端 未结 7 555
有刺的猬
有刺的猬 2020-11-29 19:51

I want to be able to host multiple NodeJS apps under the same domain, without using sub-domains (like google.com/reader instead of images.google.com). The problem is that I\

7条回答
  •  感情败类
    2020-11-29 20:15

    I was looking for this feature but for API routes, not for static files. 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

提交回复
热议问题