我正在关注课程stream-adventure。其中一项任务是创建一个 http 服务器,它将所有请求转换为大写并在响应中返回。
现在我设法让它工作并且任务通过了。但是,控制台给了我一个 TimeoutOverflowWarning。
(node:15710) TimeoutOverflowWarning: 4294967296000 does not fit into a 32-bit signed integer.
Timer duration was truncated to 2147483647.
(node:15710) TimeoutOverflowWarning: 4294967296000 does not fit into a 32-bit signed integer.
Timer duration was truncated to 2147483647.
我想知道这是内存泄漏还是由我的代码引起的,还是其他原因。因为在错误消息中提到了 32 位,所以我想知道这是否与我使用 2016 年的 Macbook Pro 以 64 位运行有关。(节点 v10.17.0)
编码:
'use-strict'
const through = require('through2')
const http = require('http')
const port = process.argv[2]
const uppercaser = through(function (buffer, _, next) {
this.push(buffer.toString().toUpperCase())
next()
});
const server = http.createServer(function (req, res) {
if (req.method === 'POST') {
res.writeHead(200, { 'Content-Type': 'text/plain' })
req.pipe(uppercaser).pipe(res)
} else {
res.writeHead(404)
res.end()
}
});
server.listen(port)