-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (35 loc) · 1.06 KB
/
index.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
import express from "express";
import axios from "axios";
import bodyParser from "body-parser";
const app = express();
const port = 3000;
const apiKey = ""; //add your own api key from openuv api
const config = {
headers: {
'x-access-token' : '', //add your own token from openuv api
}
};
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.render("index.ejs");
});
app.post("/", async (req, res) => {
const latitude = req.body.latitude;
const longitude = req.body.longitude;
try {
const response = await axios.get( `https://api.openuv.io/api/v1/uv?lat=${latitude}&lng=${longitude}`, {
headers: {
'x-access-token' : apiKey,
}
});
const uv_index = response.data.result.uv;
res.render("result.ejs", {content: uv_index});
}
catch(error) {
res.send(error.response.data);
}
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});