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
export default async function server(request: Request): Promise<Response> {
try {
const response = await fetch("https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json");
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
// Extract the vulnerabilities array
const vulnerabilities = data.vulnerabilities;
if (!vulnerabilities || !Array.isArray(vulnerabilities)) {
throw new Error("Vulnerabilities data is not in the expected format");
}
// Return the vulnerabilities array as JSON
return new Response(JSON.stringify(vulnerabilities), {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
});
} catch (error) {
console.error("Error:", error);
return new Response(JSON.stringify({ error: "Failed to fetch or process vulnerabilities data" }), {
status: 500,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
});
}
}