import { NextResponse } from 'next/server'; const CORS_HEADERS = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET,OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type,Authorization,Accept', 'Access-Control-Max-Age': '86400' }; export async function OPTIONS() { return new NextResponse(null, { status: 204, headers: CORS_HEADERS }); } async function fetchGZ(code) { const url = `https://fundgz.1234567.com.cn/js/${code}.js`; const res = await fetch(url, { cache: 'no-store' }); if (!res.ok) throw new Error('估值接口异常'); const text = await res.text(); const m = text.match(/jsonpgz\((.*)\);/); if (!m) throw new Error('估值数据解析失败'); const json = JSON.parse(m[1]); const gszzlNum = Number(json.gszzl); return { code: json.fundcode, name: json.name, dwjz: json.dwjz, gsz: json.gsz, gztime: json.gztime, gszzl: Number.isFinite(gszzlNum) ? gszzlNum : json.gszzl }; } function stripHtml(s) { return s.replace(/<[^>]*>/g, '').replace(/\s+/g, ' ').trim(); } function parseHoldings(html) { const list = []; const tableMatch = html.match(/