0

如何在节点 js 中获取当前 url?我有以下代码,但它不能正常工作。

var http = require("http");

function onRequest(request, response) {
  console.log("Request received.");
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  console.log(request.headers.host);
  response.end();
}

http.createServer(onRequest).listen(3000);

Apache 将 localhost:3000 重定向到 node.dev 域。当我运行上面的代码时,我有: localhost:3000 但我想要 node.dev (带有子域,所有 url)

4

1 回答 1

1

Ok, I have found the solution:

request.headers['x-forwarded-host']
于 2013-02-27T13:56:28.037 回答