Wednesday 16 March 2016

[koajs] this.query object is empty

Here's another noobish Node/Koa question of mine. I have the following function and this.query seems to be an empty object, no matter how I post:router.post('/', function *() { if (!this.query.location) { this.status = 400; } else { let res = yield weather.get(this.query.location, config.API_KEY); this.body = yield { temperature: { current: res.main.temp, minimum: res.main.temp_min, maximum: res.main.temp_max }, description: res.weather[0].description, humidity: res.main.humidity, visibility: res.visibility, pressure: res.main.pressure, wind: { speed: res.wind.speed, direction: res.wind.deg }, clouds: res.clouds.all, name: res.name }; } }); I've verified that I'm posting correctly (just to make sure, I tried curl --data "location=Stockholm" http://localhost:4000 as well) but the query object remains empty. Any ideas?[here's the complete app.js code]

Submitted March 16, 2016 at 03:09PM by kbrgl

No comments:

Post a Comment