-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (47 loc) · 1.33 KB
/
app.js
File metadata and controls
49 lines (47 loc) · 1.33 KB
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
const Amadeus = require("amadeus");
const express = require("express");
const app = express();
const amadeus = new Amadeus({
clientId: 'YOUR_API_KEY',
clientSecret: 'YOUR_API_SECRET',
});
const port = 3000;
app.use(express.static("public"));
app.get("/api/autocomplete", async (request, response) => {
try {
const { query } = request;
const { data } = await amadeus.referenceData.locations.get({
keyword: query.keyword,
subType: Amadeus.location.city,
});
response.json(data);
} catch (error) {
console.error(error.response);
response.json([]);
}
});
app.get("/api/search", async (request, response) => {
try {
const { query } = request;
console.log(query);
const { data } = await amadeus.shopping.flightOffersSearch.get({
originLocationCode: query.origin,
destinationLocationCode: query.destination,
departureDate: query.departureDate,
adults: query.adults,
children: query.children,
infants: query.infants,
travelClass: query.travelClass,
...(query.returnDate ? { returnDate: query.returnDate } : {}),
});
response.json(data);
} catch (error) {
console.error(error.response);
response.json([]);
}
});
app.listen(process.env.PORT || port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
//
//