2017-12-02 117 views
1

我正在使用羣集模塊在我的index.js(這是我的網站的應用程序/根目錄中的主要文件)中分發我的應用程序。現在我的應用包含很多路由。我應該包含集羣代碼來包裝我的所有路徑文件嗎?我應該在express.js中爲每個路由使用羣集嗎?

例如,

考慮我index.js文件

var cluster = require('cluster'); 
if(cluster.isMaster) 
{ 
    cluster.fork(); 
    cluster.fork(); 

    cluster.on('disconnect', function(worker) 
    { 
     console.error('disconnect!'); 
     cluster.fork(); 
    }); 
} 
else 
{ 
    var express = require('express'); 
    var app = express(); 
    app.get('/',function(req,res){ 
     //application logic goes here 
    }); 
    var route1 = require('./route1.js'); 
    app.route('/route1',route1); 
    app.listen(80); 
} 

所以,在我route1.js文件,我應該它環繞的集羣碼,就像我一樣在我index.js文件或者它已經沒有必要?

回答

0

您的羣集是最後收到http請求的羣集。他們必須知道每個集羣必須根據路線運行哪些代碼。你做這件事的方式已經是正確的。如果你正在生產項目,你可能會考慮使用流程管理器,如PM2

+0

謝謝:)現在就來! –

相關問題