2026-04-12 08:58:41 +01:00
|
|
|
import { getHtmlDocument } from '@scalar/core/libs/html-rendering';
|
2026-07-02 11:24:33 +01:00
|
|
|
import {
|
|
|
|
|
enrichPublicApiOpenApiSpec,
|
|
|
|
|
PUBLIC_API_BEARER_SCHEME,
|
|
|
|
|
PUBLIC_API_OPENAPI_URL
|
|
|
|
|
} from '@cio/utils/openapi/public-api';
|
2026-04-12 08:58:41 +01:00
|
|
|
|
2026-07-02 11:24:33 +01:00
|
|
|
export async function loader() {
|
|
|
|
|
const response = await fetch(PUBLIC_API_OPENAPI_URL);
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Response('Failed to load the public API OpenAPI specification.', { status: 502 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const spec = enrichPublicApiOpenApiSpec((await response.json()) as Record<string, unknown>);
|
2026-04-12 08:58:41 +01:00
|
|
|
|
|
|
|
|
return new Response(
|
|
|
|
|
getHtmlDocument({
|
2026-07-02 11:24:33 +01:00
|
|
|
content: JSON.stringify(spec),
|
2026-04-12 08:58:41 +01:00
|
|
|
pageTitle: 'ClassroomIO Public API Reference',
|
2026-07-02 11:24:33 +01:00
|
|
|
theme: 'none',
|
|
|
|
|
authentication: {
|
|
|
|
|
preferredSecurityScheme: PUBLIC_API_BEARER_SCHEME
|
|
|
|
|
}
|
2026-04-12 08:58:41 +01:00
|
|
|
}),
|
|
|
|
|
{
|
|
|
|
|
headers: {
|
2026-07-02 11:24:33 +01:00
|
|
|
'content-type': 'text/html; charset=utf-8',
|
|
|
|
|
'cache-control': 'public, max-age=300'
|
2026-04-12 08:58:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|