-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (28 loc) · 1.05 KB
/
server.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
/**
* HTTPS Proxy Server
*/
const PORT = process.env.PORT,
DARK_SKY_KEY = process.env.DARK_SKY_KEY,
assert = require('assert'),
querystring = require("querystring");
assert.notStrictEqual(DARK_SKY_KEY, undefined)
assert.notStrictEqual(PORT, undefined)
// TODO morgan
const app = require("express")(),
morgan = require("morgan"),
serveStatic = require('serve-static'),
https = require("https"),
fs = require("fs")
const secretKey = process.env.DARK_SKY_KEY.trim()
assert.strictEqual(secretKey.length, 32)
app.use(morgan("tiny"))
app.use(serveStatic('build', {'index': ['index.html', 'index.htm']}))
app.get('/weather/:lat/:long', function(req, res){
let queryString = querystring.stringify(req.query)
queryString.length > 0 ? queryString = "?" + queryString : void(0)
const darkSkyEndpt = `https://api.darksky.net/forecast/${secretKey}/${req.params.lat},${req.params.long}${queryString}`
https.request(darkSkyEndpt, (res2) => {
res2.setEncoding('utf8')
res2.pipe(res, {end: true})
}).end()
}).listen(PORT)