-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
geewee
committed
Mar 29, 2019
1 parent
203bbc1
commit b251e55
Showing
10 changed files
with
688 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const express = require('express'); | ||
const _ = require('lodash'); | ||
const axios = require('axios'); | ||
const memoize = require('memoizee'); | ||
|
||
const app = express(); | ||
const port = 3000; | ||
|
||
app.get('/', async (req, res, next) => { | ||
try{ | ||
const city = req.query.city; | ||
if (!city){ | ||
next(new Error("Must supply city as a parameter")) | ||
} | ||
|
||
const response = await getWeatherData(city); | ||
return res.send({ | ||
...response | ||
}); | ||
} catch (e){ | ||
next(e); | ||
} | ||
}); | ||
|
||
|
||
const getWeatherData = memoize(async (city) => { | ||
const apiKey = "89e930a8066c712e54f311a0c03fe339"; | ||
|
||
console.log("Fetching data!"); | ||
try { | ||
const response = await axios.get('http://api.openweathermap.org/data/2.5/weather', { | ||
params:{ | ||
apiKey: apiKey, | ||
q: city, | ||
units: 'metric' | ||
}}); | ||
return response.data; | ||
} catch (e){ | ||
console.log(e); | ||
throw e; | ||
} | ||
}, {maxAge: 10000}); | ||
|
||
app.listen(port, () => console.log(`Example app listening on port ${port}!`)); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "openweathermapproxy", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"repository": "https://github.com/Bambuu/openweathermapproxy.git", | ||
"author": "geewee <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "node index.js" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.18.0", | ||
"axios-cache-adapter": "^2.3.0", | ||
"express": "^4.16.4", | ||
"lodash": "^4.17.11", | ||
"memoizee": "^0.4.14", | ||
"requests": "^0.2.2" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Arguments: | ||
/usr/bin/node /usr/share/yarn/bin/yarn.js init | ||
|
||
PATH: | ||
/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/geewee/bin:/var/lib/snapd/snap/bin:/home/geewee/.local/bin | ||
|
||
Yarn version: | ||
1.13.0 | ||
|
||
Node version: | ||
10.15.0 | ||
|
||
Platform: | ||
linux x64 | ||
|
||
Trace: | ||
Error: canceled | ||
at Interface.<anonymous> (/usr/share/yarn/lib/cli.js:125657:13) | ||
at Interface.emit (events.js:182:13) | ||
at Interface._ttyWrite (readline.js:783:16) | ||
at ReadStream.onkeypress (readline.js:168:10) | ||
at ReadStream.emit (events.js:182:13) | ||
at emitKeys (internal/readline.js:424:14) | ||
at emitKeys.next (<anonymous>) | ||
at ReadStream.onData (readline.js:1022:36) | ||
at ReadStream.emit (events.js:182:13) | ||
at addChunk (_stream_readable.js:283:12) | ||
|
||
npm manifest: | ||
No manifest | ||
|
||
yarn manifest: | ||
No manifest | ||
|
||
Lockfile: | ||
No lockfile |
Oops, something went wrong.