我已将我的Node JS应用程序上传到托管:https://uberspace.de/ 我在我的app.js代码中使用" / getWeather /:town /:month /:day /:year" URL, 虽然我已经在我的本地主机上对它进行了测试,但它工作正常,并且出于某种原因在托管服务器中我无法访问输出的JSON(它没有给我结果)并且我收到错误:
Cannot GET /getWeather/berlin/4/4/2014
这是我在app.js中的代码:
app.get('/getWeather/:town/:month/:day/:year', function(req, res) {
console.log('inside getWeather');
// for avoiding crossbrowser-error
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.header('Content-type','application/json');
res.header('Charset','utf8');
var paramsW = querystring.parse(url.parse(req.url).query);
var day = req.param("day");
var month = req.param("month");
var year = req.param("year");
var town = req.param("town");
var roW = {};
parserW.addListener('end', function(result) {
roW = JSON.stringify(result);
//console.log(roW);
res.send(req.query.callback + '(' + roW + ');');
});
var requestW = require('request');
requestW('http://api.wolframalpha.com/v2/query?input=weather%20'+town+'%20'+month+'%20'+day+'%20'+year+'&appid=XXXX', function (error, responseW, body) {
if (!error && responseW.statusCode == 200) {
parserW.parseString(body, function(){
res.end();
});
}
});
});
任何想法都可能是问题? 顺便说一下,我使用其他API在相同的方法中提出了几个请求,并且它们工作正常。
非常感谢