我一直收到这个匿名错误。有人知道如何解决这个问题吗?它执行http请求,但似乎在某个地方我想念JSON.stringify。
应用.js
let server = http.createServer(function (req, res) {
path = req.url;
if (path === undefined || path === '/') {
res.end('Welcome... all-about-clash site.');
} else {
const options = {
host: 'api.clashofclans.com',
path: path,
url: 'https://api.clashofclans.com' + path,
method: 'GET',
json: true,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer token'
}
};
request(options, (error, response, body) => {
if (!error) {
res.write(JSON.stringify(body));
res.end();
} else {
res.write(JSON.stringify(error));
res.end();
}
});
}
});
这是一种奇怪的行为,http.createServer
的路线/favicon.ico
。我只需要赶上那条路线。对我有用的是:
if (req.url === '/favicon.ico') {
res.end();
return;
}
在http.createServer
方法的第一行中。