-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.js
More file actions
26 lines (22 loc) · 744 Bytes
/
proxy.js
File metadata and controls
26 lines (22 loc) · 744 Bytes
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
export default async function handler(req, res) {
const { endpoint } = req.query;
const API_KEY = process.env.API_KEY;
const BASE_URL = 'https://api.football-data.org/v4';
if (!endpoint) {
return res.status(400).json({ error: 'Endpoint is required' });
}
try {
const response = await fetch(`${BASE_URL}${endpoint}`, {
headers: {
'X-Auth-Token': API_KEY,
},
});
if (!response.ok) {
return res.status(response.status).json({ error: 'API Error' });
}
const data = await response.json();
res.status(200).json(data);
} catch (error) {
res.status(500).json({ error: 'Internal Server Error' });
}
}