Skip to content

Commit

Permalink
Add all trusted apps (dev)
Browse files Browse the repository at this point in the history
  • Loading branch information
srosset81 committed Sep 6, 2024
1 parent 9c6f411 commit 52d14d3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
6 changes: 2 additions & 4 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/** @type {import('prettier').Config} */
module.exports = {
printWidth: 120,
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
useTabs: false,
trailingComma: 'none',
arrowParens: 'avoid',

plugins: [require.resolve('prettier-plugin-astro')],

Expand Down
65 changes: 31 additions & 34 deletions src/pages/data/trusted-apps.ts
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': '*',
},
});
};

0 comments on commit 52d14d3

Please sign in to comment.