在node.js中redirect到不同的位置和端口

要将用户redirect到不同的页面,我们通常会:

res.writeHead(302, { Location: '/test' }); res.end(); 

如果我想在不同的端口上redirect他,该怎么办? 我试图添加一个字段“端口”,但似乎没有工作。

您需要指定完整的url:

 res.writeHead(302, { Location: 'http://anotherdomain.com:8888/some/path' }); res.end();