簡體   English   中英

如何在Grunt任務中保持服務器偵聽運行?

[英]How to keep server listen running in Grunt task?

我有一個HTTP服務器,這是Grunt任務的一部分。 listen方法是異步的(與大多數Node.js代碼一樣),因此Grunt任務調用該方法后,它將立即完成執行並因此關閉服務器。

grunt.registerTask('serveProxy', 'Start the proxy to the various servers', function() {
    var server = http.createServer(function(req, res) {
        // ...
    });
    server.listen(80);
});

我如何才能保持運行狀態或使方法塊不返回?

解決方案是通過告訴Grunt這是一個異步方法並使用回調指示完成的時間,以指示Grunt 根據文檔進行等待。

grunt.registerTask('serveProxy', 'Start the proxy to the various servers', function() {
    var done = this.async();
    var server = http.createServer(function(req, res) {
        // ...
    });
    server.listen(80);
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM