MCPcopy Create free account
hub / github.com/fontsource/fontsource / createContainerApp

Function createContainerApp

api/container/server.ts:25–86  ·  view source on GitHub ↗
(
	buildArtifacts: ArtifactBuilder = defaultArtifactBuilder,
)

Source from the content-addressed store, hash-verified

23 : 500;
24
25export const createContainerApp = (
26 buildArtifacts: ArtifactBuilder = defaultArtifactBuilder,
27) => {
28 const app = new Hono();
29 let buildStarted = false;
30
31 app.get('/health', (c) => c.json({ status: 200 }));
32
33 app.post('/build-version', async (c) => {
34 let payload: BuildVersionRequest | undefined;
35
36 try {
37 if (buildStarted) {
38 throw new HTTPException(409, {
39 message: 'This container instance already accepted a build.',
40 });
41 }
42 buildStarted = true;
43
44 payload = await c.req.json<BuildVersionRequest>();
45 if (!payload) {
46 throw new Error('Invalid request payload. Expected JSON body.');
47 }
48
49 const buildKey = getBuildKey(payload);
50 const startedAt = Date.now();
51 console.log(`[container] starting ${payload.mode} build ${buildKey}`);
52 const artifactCount = await buildArtifacts(payload);
53 const durationMs = Date.now() - startedAt;
54
55 console.log(
56 `[container] finished ${payload.mode} build ${buildKey} - ${artifactCount} artifacts in ${durationMs}ms`,
57 );
58
59 return c.json({ state: 'ready', buildKey });
60 } catch (error) {
61 logger.error(
62 { err: error, buildKey: payload ? getBuildKey(payload) : undefined },
63 '[container] build failed',
64 );
65
66 return c.json(
67 {
68 state: 'failed',
69 buildKey: payload ? getBuildKey(payload) : 'unknown',
70 error: error instanceof Error ? error.message : String(error),
71 },
72 errorStatus(error),
73 );
74 }
75 });
76
77 app.notFound((c) => {
78 const url = new URL(c.req.url);
79 console.warn(
80 `[container] unmatched request ${c.req.method} ${url.pathname}${url.search}`,
81 );
82 return c.json({ status: 404, error: 'Not Found.' }, 404);

Callers 2

server.test.tsFile · 0.90
server.tsFile · 0.85

Calls 8

getBuildKeyFunction · 0.90
buildArtifactsFunction · 0.85
errorStatusFunction · 0.85
getMethod · 0.65
jsonMethod · 0.65
logMethod · 0.65
errorMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected