From 1b75cf822dc339c2daf7ab9dd21c37e610c24efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E8=8E=B1Ceale?= <93030615+Ceale@users.noreply.github.com> Date: Wed, 1 May 2024 17:57:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E6=94=BEAPI=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B7=A8=E5=9F=9F=E8=AF=B7=E6=B1=82=20(#1872)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加 Access-Control-Allow-Origin: * * 完善 --------- Co-authored-by: lyswhut --- publish/changeLog.md | 1 + src/main/modules/openApi/index.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/publish/changeLog.md b/publish/changeLog.md index 0051c6b6..fab7a78c 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,6 +1,7 @@ ### 新增 - 允许添加 `m4a`、`oga` 格式的本地歌曲到列表中(#1864) +- 开放API支持跨域请求(#1872 @Ceale) ### 优化 diff --git a/src/main/modules/openApi/index.ts b/src/main/modules/openApi/index.ts index 4cd136d2..342caa1f 100644 --- a/src/main/modules/openApi/index.ts +++ b/src/main/modules/openApi/index.ts @@ -38,6 +38,7 @@ const handleSendStatus = (res: http.ServerResponse, query? const resp: Partial> = {} for (const k of keys) resp[k] = global.lx.player_status[k] res.setHeader('Content-Type', 'application/json; charset=utf-8') + res.setHeader('Access-Control-Allow-Origin', '*') res.writeHead(200) res.end(JSON.stringify(resp)) } @@ -46,6 +47,7 @@ const handleSubscribePlayerStatus = (req: http.IncomingMessage, res: http.Server 'Content-Type': 'text/event-stream', Connection: 'keep-alive', 'Cache-Control': 'no-cache', + 'Access-Control-Allow-Origin': '*', }) req.socket.setTimeout(0) req.on('close', () => { @@ -118,6 +120,7 @@ const handleStartServer = async(port: number, ip: string) => new Promise(( case '/lyric': code = 200 res.setHeader('Content-Type', 'text/plain; charset=utf-8') + res.setHeader('Access-Control-Allow-Origin', '*') msg = global.lx.player_status.lyric break case '/subscribe-player-status':