From f971de68213a75b37a17e561cee7da0f04849ab9 Mon Sep 17 00:00:00 2001 From: "3371392206@qq.com" <3371392206@qq.com> Date: Sun, 16 Aug 2026 18:43:56 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E9=A2=84=E6=A3=80=E6=B5=8B=E8=AF=95=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=20=5Fpreflight.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 该脚本仅用于本地测试,不属于项目核心代码,清理冗余文件减少项目杂乱度 --- _preflight.js | 53 --------------------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 _preflight.js diff --git a/_preflight.js b/_preflight.js deleted file mode 100644 index 67c4e5d..0000000 --- a/_preflight.js +++ /dev/null @@ -1,53 +0,0 @@ -const https = require('https'); -const base = 'test-test.zeabur.app'; - -function req(method, path, headers) { - return new Promise((resolve) => { - const r = https.request({ - hostname: base, port: 443, path, method, headers: headers || {}, - }, (res) => { - const chunks = []; - res.on('data', (c) => chunks.push(c)); - res.on('end', () => resolve({ status: res.statusCode, headers: res.headers, body: Buffer.concat(chunks) })); - }); - r.on('error', (e) => resolve({ error: e.message })); - r.end(); - }); -} - -(async () => { - // 1. 预检 OPTIONS 请求 - console.log('=== 预检: OPTIONS /v1/audio/speech (with Origin) ==='); - const r1 = await req('OPTIONS', '/v1/audio/speech', { - 'Origin': 'https://example.com', - 'Access-Control-Request-Method': 'POST', - 'Access-Control-Request-Headers': 'content-type, authorization', - }); - console.log('Status:', r1.status); - console.log('Headers:'); - for (const k of Object.keys(r1.headers)) { - if (k.startsWith('access-control') || k === 'vary') { - console.log(' ' + k + ': ' + r1.headers[k]); - } - } - console.log('Body:', r1.body ? r1.body.toString('utf8') : ''); - - // 2. 预检但无 Origin(同源或非浏览器) - console.log('\n=== OPTIONS /v1/audio/speech (NO Origin) ==='); - const r2 = await req('OPTIONS', '/v1/audio/speech', {}); - console.log('Status:', r2.status); - - // 3. 实际 POST 请求 - console.log('\n=== POST /v1/audio/speech (with Origin) ==='); - const body = JSON.stringify({ model: 'tts-1', input: 'test', voice: 'alloy' }); - const r3 = await req('POST', '/v1/audio/speech', { - 'Origin': 'https://example.com', - 'Content-Type': 'application/json', - 'Authorization': 'Bearer sk-HRNfl15pp8e0KLewaydRCmvf2KfkOYd728yLJmuff5DkyaXd', - 'Content-Length': Buffer.byteLength(body), - }); - if (r3.body) r3.write = r3.write || (() => {}); - console.log('Status:', r3.status); - console.log('Access-Control-Allow-Origin:', r3.headers['access-control-allow-origin']); - console.log('Vary:', r3.headers['vary']); -})();