Created
December 16, 2015 23:29
-
-
Save cianclarke/b05bc925685c568ed52c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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