/fred/… to stlouisfed.org and /cboe/… to cdn.cboe.com. Saved as mre_key_fred_proxy.export default {
async fetch(request, env) {
const url = new URL(request.url)
if (url.pathname === '/') {
return new Response(JSON.stringify({ status: 'FRED proxy active' }), {
headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }
})
}
let target
if (url.pathname.startsWith('/cboe/')) {
target = 'https://cdn.cboe.com' + url.pathname.replace('/cboe', '') + url.search
} else {
target = 'https://api.stlouisfed.org' + url.pathname + url.search
}
const response = await fetch(target)
const text = await response.text()
return new Response(text, {
status: response.status,
headers: { 'Content-Type': response.headers.get('Content-Type') || 'application/json', 'Access-Control-Allow-Origin': '*' }
})
}
}
-- Regime snapshots table CREATE TABLE IF NOT EXISTS regime_snapshots ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), created_at timestamptz NOT NULL DEFAULT now(), growth_score float, inflation_score float, quadrant_probabilities jsonb, transition_risk text, correlation_matrix jsonb, indicator_values jsonb ); -- Enable Row Level Security (optional but recommended) ALTER TABLE regime_snapshots ENABLE ROW LEVEL SECURITY; -- Allow all operations for authenticated and anon users CREATE POLICY "Allow all" ON regime_snapshots FOR ALL USING (true) WITH CHECK (true); -- Price cache table CREATE TABLE IF NOT EXISTS price_cache ( ticker text NOT NULL, date text NOT NULL, close float NOT NULL, PRIMARY KEY (ticker, date) ); ALTER TABLE price_cache ENABLE ROW LEVEL SECURITY; CREATE POLICY "Allow all" ON price_cache FOR ALL USING (true) WITH CHECK (true); -- Index for efficient ticker lookups CREATE INDEX IF NOT EXISTS idx_price_cache_ticker ON price_cache(ticker, date DESC);