302为临时重定向,301为永久重定向
var http = require("http");
var server = http.createServer();
server.on("request", function (req, res) {
if (req.url === "/") {
res.statusCode = 302;
res.setHeader("Location", "https://www.baidu.com/");
res.end();
}
})
server.listen(3000, function () {
console.log("server is running on port 3000");
})
网友评论