-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,55 @@ | ||
import jsonld from 'jsonld'; | ||
import eleventyFetch from "@11ty/eleventy-fetch"; | ||
import { ldpContainer } from "../../utils/ldp"; | ||
import localContext from "../../config/localContext"; | ||
import eleventyFetch from '@11ty/eleventy-fetch'; | ||
import { ldpContainer } from '../../utils/ldp'; | ||
import localContext from '../../config/localContext'; | ||
|
||
import type { APIRoute } from "astro"; | ||
import type { Resource } from "../../utils/ldp"; | ||
import type { APIRoute } from 'astro'; | ||
import type { Resource } from '../../utils/ldp'; | ||
|
||
export const prerender = false | ||
export const prerender = false; | ||
|
||
const trustedAppsUris = [ | ||
'https://dev.welcometomyplace.org/api/app' | ||
'https://dev.welcometomyplace.org/api/app', | ||
'https://dev.mutual-aid.app/api/app', | ||
'https://dev.mastopod.com/api/app', | ||
]; | ||
|
||
export const GET: APIRoute = async ({ request }) => { | ||
const trustedAppsData = [] as Resource[]; | ||
|
||
for (const appUri of trustedAppsUris) { | ||
try { | ||
// Keep response in cache for 3 hours | ||
const json = await eleventyFetch(appUri, { | ||
duration: '3h', | ||
type: 'json', | ||
// Keep response in cache for 3 hours | ||
const json = await eleventyFetch(appUri, { | ||
duration: '3h', | ||
type: 'json', | ||
fetchOptions: { | ||
headers: { 'Accept': 'application/ld+json' } | ||
} | ||
headers: { Accept: 'application/ld+json' }, | ||
}, | ||
}); | ||
const compactJson = await jsonld.compact(json, localContext); | ||
delete compactJson['@context']; | ||
trustedAppsData.push(compactJson); | ||
} catch(e) { | ||
} catch (e) { | ||
// Ignore non-available applications | ||
} | ||
} | ||
|
||
return new Response( | ||
JSON.stringify(ldpContainer(request.url, trustedAppsData)), | ||
{ | ||
status: 200, | ||
headers: { | ||
"Content-Type": "application/ld+json", | ||
"Access-Control-Allow-Origin": "*" | ||
} | ||
} | ||
); | ||
return new Response(JSON.stringify(ldpContainer(request.url, trustedAppsData)), { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/ld+json', | ||
'Access-Control-Allow-Origin': '*', | ||
}, | ||
}); | ||
}; | ||
|
||
export const HEAD: APIRoute = async () => { | ||
return new Response(undefined, | ||
{ | ||
status: 200, | ||
headers: { | ||
"Content-Type": "application/ld+json", | ||
"Access-Control-Allow-Origin": "*" | ||
} | ||
} | ||
); | ||
}; | ||
return new Response(undefined, { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/ld+json', | ||
'Access-Control-Allow-Origin': '*', | ||
}, | ||
}); | ||
}; |