ws.audioscrobbler.com 的 Node.js 代理向 www.last.fm 响应 301
我正在尝试使用 Node.js 设置 Last.fm 网络服务的代理。问题是对 ws.audioscrobbler.com 的每个请求都会被重写为 www.last.fm。例如 $curl http://localhost:8000/_api/test123
发送一个 <代码>301 永久移动 至http://www.last.fm/test123
。
var express = require('express'),
httpProxy = require('http-proxy');
// proxy server
var lastfmProxy = httpProxy.createServer(80, 'ws.audioscrobbler.com');
// target server
var app = express.createServer();
app.configure(function() {
app.use('/_api', lastfmProxy);
});
app.listen(8000);
同时 $curl http://ws.audioscrobbler.com/test123
返回常规的 404 Not Found
。我不太确定我在这里错过了什么,或者我是否以完全错误的方式处理这个问题。
I’m trying to use Node.js to set up a proxy to Last.fm’s webservices. The problem is that every request to ws.audioscrobbler.com gets rewritten to www.last.fm. So for example $ curl http://localhost:8000/_api/test123
sends a 301 Moved Permanently
to http://www.last.fm/test123
.
var express = require('express'),
httpProxy = require('http-proxy');
// proxy server
var lastfmProxy = httpProxy.createServer(80, 'ws.audioscrobbler.com');
// target server
var app = express.createServer();
app.configure(function() {
app.use('/_api', lastfmProxy);
});
app.listen(8000);
At the same time $ curl http://ws.audioscrobbler.com/test123
returns a regular 404 Not Found
. I’m not exactly sure what I’m missing here, or if I’m approaching this completely the wrong way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您收到
301 Moved Permanently
的原因是 ws.audioscrobbler.com 收到主机名“localhost”的 HTTP 请求。一种解决方案是让代理将主机名重写为“ws.audioscrobbler.com”,然后再将其传递到远程服务器:
The reason you get a
301 Moved Permanently
is that ws.audioscrobbler.com gets an HTTP request with the hostname "localhost".One solution is to let the proxy rewrite the hostname to "ws.audioscrobbler.com" before passing it on to the remote server: