-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
92 lines (84 loc) · 2.43 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const express = require("express");
const path = require("path");
const app = express();
const axios = require("axios");
require("dotenv").config();
app.use(express.static(path.join(`${__dirname}/build`)));
const port = process.env.PORT || 5000;
const server = app.listen(port, () => {
process.stdout.write(
`App listening on port ${port}!\n Press CTR C to stop the server`
);
});
app.get("/api/flights/:org/:dest/:date", async (req, res) => {
const url = `https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/browsequotes/v1.0/US/USD/en-US/${
req.params.org
}/${req.params.dest}/${req.params.date}?inboundpartialdate=2019-10-28
}`
try {
const { data } = await axios({
method: "GET",
url,
headers: {
"X-RapidAPI-Host":
"skyscanner-skyscanner-flight-search-v1.p.rapidapi.com",
"X-RapidAPI-Key":process.env.REACT_APP_API_RAPID
}
});
res.send(data);
} catch (error) {
console.log(error);
res.end();
}
});
app.get("/api/location", async (req, res) => {
try {
const { data } = await axios({
method: "POST",
url: `https://www.googleapis.com/geolocation/v1/geolocate?key=${process.env.REACT_APP_API_GEOLOCATE}`
});
res.send(data);
} catch (error) {
console.log(error);
res.end();
}
});
app.get("/api/weather/:lat/:lng", async (req, res) => {
try {
const { data } = await axios({
method: "GET",
url: `https://dark-sky.p.rapidapi.com/${req.params.lat},${
req.params.lng
}?lang=en&units=si`,
headers: {
"X-RapidAPI-Key": process.env.REACT_APP_API_DARKSKY,
"X-RapidAPI-Host": "dark-sky.p.rapidapi.com",
accept: "application/json"
}
});
res.send(data);
} catch (error) {
console.log(error);
res.end();
}
});
app.get("/api/city/:lat/:lng", async (req, res) => {
try {
const { data } = await axios({
method: "GET",
url: `https://api.flightstats.com/flex/airports/rest/v1/json/withinRadius/${req.params.lng}/${req.params.lat
}/50?appId=3e66f39b&appKey=${process.env.REACT_APP_API_FLIGHTSTATS}`
});
const arr = Array.from(data.airports);
const item = arr.find((elt) => {
return elt.classification === 1 || 2 || 3;
});
res.send({ city: item.city, cityCode: item.cityCode });
} catch (error) {
console.log(error);
res.end();
}
});
app.get("/connect", async (req, res) => {
res.send("Connected");
});