-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy-server.js
More file actions
86 lines (76 loc) · 2.87 KB
/
proxy-server.js
File metadata and controls
86 lines (76 loc) · 2.87 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
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
const express = require("express");
const cors = require("cors");
const axios = require("axios");
const app = express();
const PORT = 5000;
// CORS middleware
app.use(cors());
app.use(express.json());
// Recipe API proxy endpoint
app.get("/api/recipes", async (req, res) => {
try {
const { q, mealType } = req.query;
// Edamam API anahtarları (.env dosyasından)
const APP_ID = process.env.REACT_APP_APP_ID || "a658d166";
const APP_KEY =
process.env.REACT_APP_APP_KEY || "873bde986100aef8b561fc76713c9a2f";
const url = `https://api.edamam.com/api/recipes/v2?q=${encodeURIComponent(
q
)}&app_id=${APP_ID}&app_key=${APP_KEY}&type=public`;
console.log("Fetching from:", url);
const response = await axios.get(url);
if (response.data && response.data.hits) {
res.json(response.data);
} else {
console.log("API Response:", response.data);
res.status(500).json({ error: "Invalid API response format" });
}
} catch (error) {
console.error("API Error Details:", {
message: error.message,
status: error.response?.status,
data: error.response?.data,
});
// Mock data döndür
const mockData = {
hits: [
{
recipe: {
id: "1",
label: `${req.query.q || "Chicken"} Tarifi`,
image: "https://via.placeholder.com/300x200?text=Recipe+Image",
url: "https://example.com",
ingredientLines: [
`${req.query.q || "Chicken"} - 500g`,
"Tuz - 1 çay kaşığı",
"Karabiber - 1 çay kaşığı",
"Zeytinyağı - 2 yemek kaşığı",
],
healthLabels: ["Low-Carb", "High-Protein"],
dishType: ["main course"],
mealType: [
req.query.mealType?.toLowerCase() || "breakfast",
],
totalWeight: 500,
totalNutrients: {
CHOLE: {
label: "Cholesterol",
quantity: 50,
unit: "mg",
},
ENERC_KCAL: {
label: "Energy",
quantity: 300,
unit: "kcal",
},
},
},
},
],
};
res.json(mockData);
}
});
app.listen(PORT, () => {
console.log(`Proxy server running on port ${PORT}`);
});