-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwxproxy.js
34 lines (28 loc) · 1.08 KB
/
wxproxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env nodejs
'use strict';
/* This program expects these environment variables:
GOOGLE_KEY API Key for Google Geolocation API
DARK_SKY_KEY API key for Dark SKY
LANGUAGE Language for Dark Sky API calls
PORT Port for the Express HTTP server
*/
require('dotenv-defaults').config();
const simplesky = require('simplesky');
const express = require('express');
const app = express();
const PORT = (process.env.PORT || 5000);
const wxAPI = new simplesky(process.env.GOOGLE_KEY, process.env.DARK_SKY_KEY, process.env.LANGUAGE, 'auto');
app.get('/:lat/:lng/:exclude', (req, res) => {
console.log(req.params);
let lat = req.params.lat;
let lng = req.params.lng;
let location = null; // Google API still a mystery
let exclude = [req.params.exclude]; // Optional
wxAPI.getWeather(location, lat, lng, exclude).then((wx) => {
res.json(wx);
}).catch((err) => {
console.log(err);
});
});
// listen for requests :)
app.listen(PORT, () => console.log(`Wx API is listening on port ${PORT}`));