f0752b804b
FREE ESPN news wire + championship-winner futures for the never-dark
offseason hub. Both graceful/empty, never fabricate a market value.
- newsService (mirrors injuryService): per-sport ESPN /news FEEDS, pure
parseNews → { sport, items:[{id,headline,description,published,type,
athlete?{name,key},team?,href}] }; athlete/team from categories[] only
(absent when not present). Cache 15m, injectable, offline-tested.
- oddsNormalizer.normalizeOutrights: NEW branch — outrights outcomes are
{name,price} with no point, so normalizeProps drops them; keeps them with
best-price-across-allowed-books per selection. + americanToDecimal.
- oddsService.FUTURES_KEYS: separate map (mlb/nba/wnba championship winner),
OUT of the daily SPORT_KEYS/snapshot budget.
- futuresService: getFutures(sport,deps) → { sport, updated_at, markets:
[{key,title,selections:[{name,price,prevPrice?,move?}]}] }. One outrights
call per 12h TTL (quota-disciplined), FUTURES_ENABLED gate. Price-move
(shortening/drifting/flat) mirrors computeLineDeltas SHAPE on odds not
line; prev prices persisted inside the futures:{sport} value (no new key).
linkNewsToMoves pure causal-tie helper.
- Routes /api/news/:sport + /api/futures/:sport (registered) + Next proxies.
- Tests: newsService, futuresService, oddsNormalizerOutrights (fail→pass,
no network). Full suite green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3000';
|
|
|
|
/**
|
|
* Futures proxy (Wave 2A, S25 rule). Forwards to the Express
|
|
* `/api/futures/:sport` (quota-disciplined championship outrights).
|
|
* Degrades to an empty-but-valid board so the hub never blows up.
|
|
*/
|
|
export async function GET(req: NextRequest, { params }: { params: Promise<{ sport: string }> }) {
|
|
const { sport } = await params;
|
|
const sportLc = String(sport || '').toLowerCase();
|
|
const qs = req.nextUrl.search;
|
|
try {
|
|
const upstream = await fetch(`${BACKEND_URL}/api/futures/${encodeURIComponent(sportLc)}${qs}`, {
|
|
method: 'GET',
|
|
headers: { Accept: 'application/json' },
|
|
});
|
|
const data = await upstream.json().catch(() => ({}));
|
|
if (!upstream.ok) return NextResponse.json(data, { status: upstream.status });
|
|
return NextResponse.json(data);
|
|
} catch {
|
|
return NextResponse.json({ sport: sportLc, updated_at: new Date().toISOString(), markets: [] });
|
|
}
|
|
}
|