重定向node.js中的其他位置和端口

时间:2014-02-06 13:16:09

标签: node.js http redirect

要将用户重定向到其他页面,我们通常会这样做:

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

如果我想将他重定向到另一个端口怎么办?我试图添加一个字段'端口',但它似乎不起作用。

1 个答案:

答案 0 :(得分:3)

您需要指定完整的网址:

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