Skip to content

Instantly share code, notes, and snippets.

@cianclarke
Created December 16, 2015 23:29
Show Gist options
  • Save cianclarke/b05bc925685c568ed52c to your computer and use it in GitHub Desktop.
Save cianclarke/b05bc925685c568ed52c to your computer and use it in GitHub Desktop.
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');
var request = require('request');
function helloRoute() {
var hello = new express.Router();
hello.use(cors());
hello.use(bodyParser());
hello.all('/', function(req, res) {
var location = req.query.location || req.body.location;
return request({
url : 'http://api.openweathermap.org/data/2.5/weather',
json : true,
qs : {
appid : "2de143494c0b295cca9337e1e96b00e0",
q : location
}
}, function(err, response, body){
if (err){
return res.status(500).json(err);
}
return res.json(body);
});
});
return hello;
}
module.exports = helloRoute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment