-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (43 loc) · 1.59 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
console.log("IS_PRODUCTION: ", process.env.IS_PRODUCTION)
if(!process.env.IS_PRODUCTION){
require('dotenv').config()
console.log("App is NOT running in \"production\".")
} else {
console.log("App is running in \"production\".")
}
const VISUALCROSSING_API_KEY = process.env.VISUALCROSSING_API_KEY
const axios = require('axios')
const express = require('express')
const app = express()
const port = process.env.PORT || 8080
app.use(express.json())
app.use(express.static('public'))
// app.get("/", (req, res) => {
// res.render('index.html');
// })
app.post('/weather', (req, res) => {
const url = `https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/`
+ `${req.body.latitude}%2C%20${req.body.longitude}?unitGroup=us`
+ `&include=hours%2Cdays`
+ `&key=${VISUALCROSSING_API_KEY}`
+ `&contentType=json`
const url2 = `https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/weatherdata/forecast?locations=`
+ `${req.body.latitude}%2C%20${req.body.longitude}`
+ `&includeAstronomy=true`
+ `&aggregateHours=1`
+ `&unitGroup=us`
+ `&forecastDays=2`
+ `&shortColumnNames=false`
+ `&contentType=json`
+ `&key=${VISUALCROSSING_API_KEY}`
axios({
url: url2,
responseType: 'json'
}).then(data => res.json(data.data))
.catch(err => {
console.error(err);
});
})
app.listen(port, () => {
console.log(`Server started on port ${port}`);
})