Nodeschool 的 Stream-Adventure #7 HTTP 服务器

Nodeschool's Stream-Adventure #7 HTTP Server

我在 Nodeschool 的流冒险练习 #7 - Http 服务器中做错了。这是一个练习描述 gist.

这是我到目前为止完成的代码:

var http = require('http');
var through = require('through2');

var server = http.createServer(function (req, res) {
    if (req.method != 'POST') 
        return;

    var stream = through(function write(buffer, encoding, next) {
           this.push(buffer.toString().toUpperCase());
           next();
       });

    req.pipe(stream).pipe(res);
});
server.listen(process.argv[2]);

我在验证时遇到 "not ok 3 successful exit code" 错误。所以我虽然有些事情:

现在,我看到 here 几年前这个练习有问题。真的正确吗? 如果是,有人可以提示我做错了什么吗?

谢谢。

今天睡了一觉,头脑清醒的我试着重新掌握测试用例。所以我在

中看到
ps.once('exit', function (code) { 
    t.equal(Number(code), 0, 'successful exit code'); 
});

它期望成功 return (0)。我将 console.log(code) 放入其中,结果为 143(SIGTERMed 进程)。那是因为第 48 行(ps.kill),它杀死了 过程。所以我将测试代码从预期的 0 更改为 143。它成功了。但是即使看到它成功了,我仍然没有看解决方案。我想 使原始测试代码工作。所以我 google 了一下,发现了这个:

process.on('SIGTERM', function() {
    process.exit();
});

当我将其放入代码中时,它终于起作用了。现在我终于检查了 solition 和参考解决方案没有工作。正如我从问题描述中预期的那样。 不管怎样,我已经做到了,并且学到了比我预期的要多得多的知识。希望这对某人有所帮助。

编辑:

当我尝试为此打开问题报告时 (link), I realize that there was already a report on this subject (link)。真正的问题是我试图将 stream-adventure 与旧版本的 Node (0.10.33) 一起使用,而这个问题不会发生在较新的 0.12.0(我写这篇文章时的最新版本)中。