Node.js表达多租户应用程序

时间:2015-09-09 13:25:07

标签: node.js express multi-tenant

我们正计划在node.js中使用多租户应用,并使用mongodb表达。我们将通过REST API公开一些核心功能。我们将为每个客户定制功能,这些功能将处理一些数据,然后调用REST API。每个客户的自定义功能以及UI(视图和公用文件夹)将驻留在父文件夹下的每个客户的单独文件夹中。我的问题是:

  1. 当我添加新客户并为他创建模块时,我应该可以开始使用它而无需重新启动主模块(app.js)。
  2. 我需要根据网址将客户重定向到他的UI文件,例如example.com/cust1/home会转到父文件夹/ cust1 / views,而example.com/cust2/home会转到parentfolder / cust2 / views
  3. 对于原型,我们在apache代理/反向代理后面运行节点,并在自己的端口上运行自定义应用程序。但是在生产中我们不能让这些应用在很多单独的端口上运行,或者每次都修改default.conf。对于UI,我们尝试了快速的动态路由,但是没有用。我们尝试在app.js中执行此操作:

    var cust1 = require('./cust1/custommodule'); //this needs to be done for each new customer module added;
    var app = express();
    
    // view engine setup
    var basePath = ''; //works if we hard code it to cust1 or cust2 here;
    app.use('/', function(req, res, next){
    //      basePath = path.dirname(req.originalUrl); //this does not work since the app.set is executed before this is assigned
            app.engine('html', require('ejs').__express);
            app.set('view engine', 'html');
            app.set('views', path.join(__dirname, basePath + '/views'));
            next();
    });
    
    app.use('/:custom', express.static(__dirname + basePath + '/public'));
    app.use('/cust1', cust1); //request coming with /cust1 should use this module, but this again needs to be done for each new customer module added;
    

    不确定这是否正确。任何指针都会受到赞赏。

0 个答案:

没有答案
相关问题