Skip to content

Commit 194297b

Browse files
committed
Added membership route to get plans and features
1 parent 5f2a6b8 commit 194297b

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/pages/api/membership.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export default async function handler(req, res) {
2+
try {
3+
// Construct the external API URL with query parameters
4+
const queryParams = req.url.includes("?") ? req.url.split("?")[1] : "";
5+
const apiUrl = `${process.env.API_URL}/membership${
6+
queryParams ? `?${queryParams}` : ""
7+
}`;
8+
9+
// Call the external API with the required headers
10+
const response = await fetch(apiUrl, {
11+
method: "GET",
12+
headers: {
13+
"Content-Type": "application/json",
14+
key: process.env.ACCESS_KEY,
15+
},
16+
});
17+
18+
// Handle errors from the external API
19+
if (!response.ok) {
20+
const errorData = await response.text(); // Capture the error response
21+
console.error("API Error Response:", errorData);
22+
return res
23+
.status(response.status)
24+
.json({ message: "Error fetching membership data", error: errorData });
25+
}
26+
27+
// Parse and return the response
28+
const data = await response.json();
29+
res.status(200).json(data);
30+
} catch (error) {
31+
console.error("Internal Server Error:", error); // Log full error details
32+
res
33+
.status(500)
34+
.json({ message: "Internal Server Error", error: error.message });
35+
}
36+
}

0 commit comments

Comments
 (0)