-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththirdPartyApi.js
48 lines (35 loc) · 1.25 KB
/
thirdPartyApi.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
import express from "express";
import fetch from "node-fetch";
import { mockGoogleApiData } from "./mockGoogleApiData .js";
const router = express.Router();
router.get("/mealImages", async (req, res) => {
const url = `https://www.themealdb.com/api/json/v1/1/filter.php?c=vegetarian`;
try {
const mealDBApiResponse = await fetch(url);
if (!mealDBApiResponse.ok) throw await mealDBApiResponse.json();
return res.json(await mealDBApiResponse.json());
} catch (error) {
console.log(error);
return res.status(400).json({ error: "Failed to get images" });
}
});
// MOCK-API-DATA FETCHING
router.get("/reviews", async (req, res) => {
res.json(mockGoogleApiData);
});
/*
// REAL API FETCHING --- Don't Delete
router.get("/reviews", async (req, res) => {
const url = `https://maps.googleapis.com/maps/api/place/details/json?placeid=${process.env.PLACE_ID}&key=${process.env.GOOGLE_API}`;
try {
const googleApiResponse = await fetch(url);
if (!googleApiResponse.ok) throw await googleApiResponse.json();
console.log(googleApiResponse);
return res.json(await googleApiResponse.json());
} catch (error) {
console.log(error);
return res.status(400).json({ error: "Failed to get reviews" });
}
});
*/
export default router;