(req: FastifyRequest<{ Params: { query: string } }>, res: FastifyReply)
| 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}`; |
nothing calls this directly
no test coverage detected