MCPcopy Create free account
hub / github.com/Sandpack/nodebox-runtime / moduleQueryMiddleware

Method moduleQueryMiddleware

tests/setup/MockCdn.ts:53–68  ·  view source on GitHub ↗
(req: FastifyRequest<{ Params: { query: string } }>, res: FastifyReply)

Source from the content-addressed store, hash-verified

51 }
52
53 private moduleQueryMiddleware(req: FastifyRequest<{ Params: { query: string } }>, res: FastifyReply): void {
54 res.header('access-control-allow-origin', '*');
55 const parsedQuery = atob(req.params.query);
56
57 for (const pkg of this.packages) {
58 const pkgPragma = this.getPackagePragma(pkg.name, pkg.version);
59
60 if (parsedQuery === pkgPragma) {
61 this.respondWith(res, pkg.files);
62 return;
63 }
64 }
65
66 // Otherwise, respond with a 404.
67 res.status(401).send(`Unknown dependency "${parsedQuery}"`);
68 }
69
70 private getPackagePragma(pkgName: string, packageVersion: string): string {
71 return `${pkgName}@${packageVersion}`;

Callers

nothing calls this directly

Calls 3

getPackagePragmaMethod · 0.95
respondWithMethod · 0.95
sendMethod · 0.45

Tested by

no test coverage detected