Skip to content

Commit b251e55

Browse files
author
geewee
committed
finished proxy
1 parent 203bbc1 commit b251e55

File tree

10 files changed

+688
-0
lines changed

10 files changed

+688
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/openweathermapproxy.iml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const express = require('express');
2+
const _ = require('lodash');
3+
const axios = require('axios');
4+
const memoize = require('memoizee');
5+
6+
const app = express();
7+
const port = 3000;
8+
9+
app.get('/', async (req, res, next) => {
10+
try{
11+
const city = req.query.city;
12+
if (!city){
13+
next(new Error("Must supply city as a parameter"))
14+
}
15+
16+
const response = await getWeatherData(city);
17+
return res.send({
18+
...response
19+
});
20+
} catch (e){
21+
next(e);
22+
}
23+
});
24+
25+
26+
const getWeatherData = memoize(async (city) => {
27+
const apiKey = "89e930a8066c712e54f311a0c03fe339";
28+
29+
console.log("Fetching data!");
30+
try {
31+
const response = await axios.get('http://api.openweathermap.org/data/2.5/weather', {
32+
params:{
33+
apiKey: apiKey,
34+
q: city,
35+
units: 'metric'
36+
}});
37+
return response.data;
38+
} catch (e){
39+
console.log(e);
40+
throw e;
41+
}
42+
}, {maxAge: 10000});
43+
44+
app.listen(port, () => console.log(`Example app listening on port ${port}!`));

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "openweathermapproxy",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"repository": "https://github.com/Bambuu/openweathermapproxy.git",
6+
"author": "geewee <[email protected]>",
7+
"license": "MIT",
8+
"scripts": {
9+
"start": "node index.js"
10+
},
11+
"dependencies": {
12+
"axios": "^0.18.0",
13+
"axios-cache-adapter": "^2.3.0",
14+
"express": "^4.16.4",
15+
"lodash": "^4.17.11",
16+
"memoizee": "^0.4.14",
17+
"requests": "^0.2.2"
18+
}
19+
}

yarn-error.log

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Arguments:
2+
/usr/bin/node /usr/share/yarn/bin/yarn.js init
3+
4+
PATH:
5+
/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
6+
7+
Yarn version:
8+
1.13.0
9+
10+
Node version:
11+
10.15.0
12+
13+
Platform:
14+
linux x64
15+
16+
Trace:
17+
Error: canceled
18+
at Interface.<anonymous> (/usr/share/yarn/lib/cli.js:125657:13)
19+
at Interface.emit (events.js:182:13)
20+
at Interface._ttyWrite (readline.js:783:16)
21+
at ReadStream.onkeypress (readline.js:168:10)
22+
at ReadStream.emit (events.js:182:13)
23+
at emitKeys (internal/readline.js:424:14)
24+
at emitKeys.next (<anonymous>)
25+
at ReadStream.onData (readline.js:1022:36)
26+
at ReadStream.emit (events.js:182:13)
27+
at addChunk (_stream_readable.js:283:12)
28+
29+
npm manifest:
30+
No manifest
31+
32+
yarn manifest:
33+
No manifest
34+
35+
Lockfile:
36+
No lockfile

0 commit comments

Comments
 (0)