web/src/pages/api/awesome-privacy.json.ts
21 lines · 672 bytes
1import type { APIRoute } from 'astro';
2import yaml from 'js-yaml';
3
4import type { AwesomePrivacy } from '../../types/Service';
5
6const awesomePrivacyYamlPath = 'https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/awesome-privacy.yml';
7
8export const GET: APIRoute = async () => {
9
10 const yamlContent = await fetch(awesomePrivacyYamlPath)
11 .then(response => response.text())
12 .catch(error => {
13 return JSON.stringify({ error: "Failed to fetch YAML file", details: error });
14 });
15
16 const yamlObject = yaml.load(yamlContent) as AwesomePrivacy;
17
18 return new Response(
19 JSON.stringify(yamlObject), { headers: { 'content-type': 'application/json' } }
20 )
21}