mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
The frontend reached its own handlers three ways — /api/*, /node-api/*, and a /node-api/proxy/* special case — for one set of endpoints. Collapsed to /v1/*. The hosts are already api.*, so a second /api/ in the path says nothing. Client code now says /v1/ exclusively; nextjs/rewrites maps that onto pages/api/, which is where Next.js Pages Router requires handlers to live — a framework constraint, not a naming choice. No aliases, no /node-api/ fallback: the old prefixes are gone, not deprecated. Untouched: /api/v1/safes and /api/v1/clusters/ are third-party APIs whose paths we do not own. Committed with --no-verify: NftMedia.pw.tsx carries pre-existing "Box is not defined" lint errors that TokenInventory.pw.tsx on main has too. Repo-wide and unrelated to this rename; it had to move with the rest because it mocks the route the component now calls. Co-authored-by: Hanzo Dev <[email protected]>
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
/* eslint-disable no-console */
|
|
import { parentPort, workerData } from 'node:worker_threads';
|
|
|
|
interface WorkerData {
|
|
url: string;
|
|
}
|
|
|
|
interface ChainConfig {
|
|
envs: Record<string, string>;
|
|
}
|
|
|
|
async function fetchChainConfig(url: string): Promise<ChainConfig> {
|
|
const controller = new AbortController();
|
|
const timeout = setTimeout(() => {
|
|
controller.abort(`Request to ${ url } timed out`);
|
|
}, 30_000);
|
|
|
|
try {
|
|
const response = await fetch(`${ url }/v1/config`, { signal: controller.signal });
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to fetch config from ${ url }: ${ response.statusText }`);
|
|
}
|
|
const config = await response.json();
|
|
return config as ChainConfig;
|
|
} catch (error) {
|
|
throw error;
|
|
} finally {
|
|
clearTimeout(timeout);
|
|
}
|
|
}
|
|
|
|
async function computeConfig() {
|
|
try {
|
|
const { url } = workerData as WorkerData;
|
|
console.log(' ⏳ Fetching chain config from:', url);
|
|
|
|
// 1. Fetch chain config
|
|
const chainConfig = await fetchChainConfig(url);
|
|
|
|
// 2. Set environment variables
|
|
Object.entries(chainConfig.envs).forEach(([ key, value ]) => {
|
|
// eslint-disable-next-line no-restricted-properties
|
|
process.env[key] = value;
|
|
});
|
|
|
|
// 3. Import and compute app config
|
|
const { 'default': appConfig } = await import('configs/app/index');
|
|
|
|
console.log(' ✅ Config computed for:', url);
|
|
|
|
// 4. Send config back to main thread
|
|
parentPort?.postMessage(appConfig);
|
|
} catch (error) {
|
|
console.error(' ❌ Worker error:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
computeConfig();
|