Api ws.audioscrobbler.com的Node.js代理以301响应www.last.fm
我正在尝试使用Node.js来设置一个到Last.fm的webservices的代理。问题是对ws.audioscrobbler.com的每个请求都会被重写到www.last.fm。因此,例如Api ws.audioscrobbler.com的Node.js代理以301响应www.last.fm,api,redirect,node.js,proxy,last.fm,Api,Redirect,Node.js,Proxy,Last.fm,我正在尝试使用Node.js来设置一个到Last.fm的webservices的代理。问题是对ws.audioscrobbler.com的每个请求都会被重写到www.last.fm。因此,例如$curl\u api/test123将永久移动的301发送到http://www.last.fm/test123 var express=require('express'), httpProxy=require('http-proxy'); //代理服务器 var lastfmProxy=httpPro
$curl\u api/test123
将永久移动的301发送到http://www.last.fm/test123
var express=require('express'),
httpProxy=require('http-proxy');
//代理服务器
var lastfmProxy=httpProxy.createServer(80,'ws.audioscrobbler.com');
//目标服务器
var app=express.createServer();
app.configure(函数(){
应用程序使用('/_api',lastfmProxy);
});
app.listen(8000);
同时,$curl
返回一个常规的404未找到
。我不确定我在这里遗漏了什么,或者我是不是完全错了。永久移动301的原因是ws.audioscrobbler.com收到一个主机名为“localhost”的HTTP请求
一种解决方案是让代理在将主机名传递到远程服务器之前将主机名重写为“ws.audioscrobbler.com”:
var httpProxy = require('http-proxy');
var lastfmProxy = httpProxy.createServer(function (req, res, proxy) {
req.headers.host = 'ws.audioscrobbler.com';
proxy.proxyRequest(req, res, {
host: 'ws.audioscrobbler.com',
port: 80,
});
}).listen(8000);