Skip to content

Commit

Permalink
finished proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
geewee committed Mar 29, 2019
1 parent 203bbc1 commit b251e55
Show file tree
Hide file tree
Showing 10 changed files with 688 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/openweathermapproxy.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions index.js
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}!`));
19 changes: 19 additions & 0 deletions package.json
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"
}
}
36 changes: 36 additions & 0 deletions yarn-error.log
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
Loading

0 comments on commit b251e55

Please sign in to comment.