http - How to redirect user's browser URL to a different page in Nodejs? -
in application i'm trying write, main page (http://localhost:8675) has following form:
<form action='/?joinnew' method='post'> <button>start</button> </form>
here code in server.js:
http.createserver(function(request, response) { var root = url.parse(request.url).pathname.split('/')[1]; if (root == '') { var query = url.parse(request.url).search: if (query == '?joinnew') { var newroom = getavaliableroomid(); // '8dn1u', 'idjh1', '8jm84', etc. // redirect user's web browser new url // ??? how do. need redirect 'http://whateverhostthiswillbe:8675/'+newroom ... }}}
i love if there way didn't have know host address, since changing.
the 'http' object regular require('http'), not require('express').
response.writehead(301, {location: 'http://whateverhostthiswillbe:8675/'+newroom} ); response.end();
Comments
Post a Comment