我在节点中有一个脚本,我想自动重定向到我在一个数组中拥有的随机链接,页面是白色的,当我放置 maths.random 函数时不会重定向
有我的代码:
const http = require('http');
let randURLs = [
"aaaaa",
"xxxxx",
"bbbbb"
];
const server = http.createServer(function(req, res) {
if (req.method === 'POST') {
console.log('post method')
}
else {
let randNumber = Math.floor(Math.random()*randURLs.length);
res.writeHead(301,{Location: 'https://www.test.com/' +
randURLs[randNumber]});
}
res.end();
});
server.listen(4000);
console.log("localhost:1337 ...");
我想重定向到https://www.test.com/randomValueInMyArray
谢谢,本杰明