网址重定向

时间:2013-12-02 05:21:08

标签: node.js redirect

我在下面的代码中做错了什么

 var path = 'http://' + someip + ':' + port ;
 //var path = "http://someip:1000/";  // This is working
 res.writeHead(302, {'Location': path});

对此的任何帮助都会非常有用。

1 个答案:

答案 0 :(得分:2)

很难通过两行来理解你的问题,你可能会做其他错误的事情。这应该是你要找的。

var express = require('express');
var app = express();

var someip = '127.0.0.1';
var port = '8080';

app.get('/hello.txt', function(req, res){
  var path = 'http://' + someip + ':' + port ;
  body = 'Redirecting to ' + path;
  res.writeHead(302, {'Location': path, 'Content-Type': 'text/html'});
  res.end(body);
});

app.listen(3000);
相关问题