为什么我的Node.js ServerResponse **被代理包裹**没有响应?

问题描述 投票:0回答:1

这必须是一个非常具体且奇怪的问题。

显然很有效,

import http from 'http';

http.createServer(function(_req, res) {
  res.end('yeah!');
}).listen(3000);

但是不是。服务器没有响应请求。

import http from 'http';

http.createServer(function(_req, res) {
  const pres = new Proxy(res, {});
  pres.end('yeah!');
}).listen(3000);

由于某种原因,我需要包装ServerResponse ...我正在调试,但是没有任何提示。 这样的代理对象与原始对象有什么不同?符号?属性定义?如果有人知道这一点,请发表。任何信息将不胜感激。

javascript node.js ecmascript-next
1个回答
0
投票
import http from 'http'; http.createServer(function(_req, res) { const pres = new Proxy(res, { get(t, p, r) { const v = Reflect.get(t, p, r); if (typeof v === 'function') return v.bind(t); return v; }, }); pres.end('yeah!'); }).listen(3000);

Da。

© www.soinside.com 2019 - 2024. All rights reserved.