| 8 | |
| 9 | // Fetch latest metadata from metadata worker |
| 10 | export const getMetadata = async (id: string, req: Request, env: Env) => { |
| 11 | const apiPathname = `/v1/fonts/${id}`; |
| 12 | const url = new URL(req.url); |
| 13 | url.pathname = apiPathname; |
| 14 | |
| 15 | // Update incoming request to use new pathname |
| 16 | const newRequest = new Request(url.toString(), { |
| 17 | ...req.clone(), |
| 18 | method: 'GET', |
| 19 | }); |
| 20 | const metadata = await env.METADATA.fetch(newRequest); |
| 21 | if (!metadata.ok) { |
| 22 | const error = await metadata.json<StatusErrorObject>(); |
| 23 | throw new StatusError( |
| 24 | metadata.status, |
| 25 | `Bad response from metadata worker. ${error.error}`, |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | return await metadata.json<IDResponse>(); |
| 30 | }; |
| 31 | |
| 32 | export const getVariableMetadata = async ( |
| 33 | id: string, |