How to redirect user's browser URL to a different page in Nodejs?
Solution 1:
To effect a redirect, you send a redirect status (301 for permanent redirect, 302 for a "this currently lives on ..." redirect, and 307 for an intentional temporary redirect):
response.writeHead(301, {
Location: `http://whateverhostthiswillbe:8675/${newRoom}`
}).end();
Solution 2:
For those who (unlike OP) are using the express lib:
http.get('*',function(req,res){
res.redirect('http://exmple.com'+req.url)
})
Solution 3:
OP: "I would love if there were a way to do it where I didn't have to know the host address..."
response.writeHead(301, {
Location: "http" + (request.socket.encrypted ? "s" : "") + "://" +
request.headers.host + newRoom
});
response.end();