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