在我尝试编写的应用程序中,主页(http:// localhost:8675)具有以下形式:
<form action='/?joinnew' method='post'> <button>Start</button> </form>
这是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 the user's web browser to a new url // ??? How to do. Need to redirect to 'http://whateverhostthiswillbe:8675/'+newRoom ... }}}
我希望能在不需要知道主机地址的地方进行处理,因为这种情况可能会发生变化。
“ http”对象是常规的require(’http’),而不是require(’express’)。
response.writeHead(301, {Location: 'http://whateverhostthiswillbe:8675/'+newRoom} ); response.end();