mirror of
https://github.com/hanzoai/catalog.git
synced 2026-10-30 18:46:06 +00:00
Serves the public read-only catalog (models, pricing, plans; extensible via src/registry.js) from a Cloudflare Worker at catalog.hanzo.ai, so cloud-api can drop AUTH_PUBLIC_PATHS and be fully authenticated. Serving order (never empty): Cache API -> KV -> origin (pricing.hanzo.ai) read-through -> bundled snapshot. Daily cron refreshes KV + warms the edge. Authorization-bearing requests are proxied to authed cloud-api (auth-branch).
29 lines
1.3 KiB
JavaScript
29 lines
1.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Regenerate src/snapshot.json — the cold-start / origin-down fallback the worker
|
|
* serves before the first cron populates KV (and if both KV and origin are ever
|
|
* unavailable at once). KV is the durable store in production; this bundled copy
|
|
* only guarantees the edge is never empty. Run: `npm run snapshot`.
|
|
*/
|
|
import { writeFileSync } from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { dirname, join } from 'node:path';
|
|
import { REGISTRY, PATHS } from '../src/registry.js';
|
|
|
|
const OUT = join(dirname(fileURLToPath(import.meta.url)), '..', 'src', 'snapshot.js');
|
|
|
|
const snapshot = {};
|
|
for (const path of PATHS) {
|
|
const { origin } = REGISTRY[path];
|
|
process.stdout.write(`[snapshot] GET ${origin} ... `);
|
|
const res = await fetch(origin, { headers: { accept: 'application/json' } });
|
|
if (!res.ok) throw new Error(`${origin} -> HTTP ${res.status}`);
|
|
snapshot[path] = await res.json();
|
|
console.log(`ok (${JSON.stringify(snapshot[path]).length} bytes)`);
|
|
}
|
|
|
|
snapshot.__generated = new Date().toISOString();
|
|
const banner = '// GENERATED by scripts/snapshot.mjs — cold-start / origin-down fallback. Do not edit by hand.\n';
|
|
writeFileSync(OUT, banner + 'export default ' + JSON.stringify(snapshot) + ';\n');
|
|
console.log(`[snapshot] wrote ${OUT} (${PATHS.length} resources)`);
|