开放API支持跨域请求 (#1872)
* 增加 Access-Control-Allow-Origin: * * 完善 --------- Co-authored-by: lyswhut <lyswhut@qq.com>pull/1989/head
parent
60604020c7
commit
1b75cf822d
|
@ -1,6 +1,7 @@
|
||||||
### 新增
|
### 新增
|
||||||
|
|
||||||
- 允许添加 `m4a`、`oga` 格式的本地歌曲到列表中(#1864)
|
- 允许添加 `m4a`、`oga` 格式的本地歌曲到列表中(#1864)
|
||||||
|
- 开放API支持跨域请求(#1872 @Ceale)
|
||||||
|
|
||||||
### 优化
|
### 优化
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ const handleSendStatus = (res: http.ServerResponse<http.IncomingMessage>, query?
|
||||||
const resp: Partial<Record<SubscribeKeys, any>> = {}
|
const resp: Partial<Record<SubscribeKeys, any>> = {}
|
||||||
for (const k of keys) resp[k] = global.lx.player_status[k]
|
for (const k of keys) resp[k] = global.lx.player_status[k]
|
||||||
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
||||||
|
res.setHeader('Access-Control-Allow-Origin', '*')
|
||||||
res.writeHead(200)
|
res.writeHead(200)
|
||||||
res.end(JSON.stringify(resp))
|
res.end(JSON.stringify(resp))
|
||||||
}
|
}
|
||||||
|
@ -46,6 +47,7 @@ const handleSubscribePlayerStatus = (req: http.IncomingMessage, res: http.Server
|
||||||
'Content-Type': 'text/event-stream',
|
'Content-Type': 'text/event-stream',
|
||||||
Connection: 'keep-alive',
|
Connection: 'keep-alive',
|
||||||
'Cache-Control': 'no-cache',
|
'Cache-Control': 'no-cache',
|
||||||
|
'Access-Control-Allow-Origin': '*',
|
||||||
})
|
})
|
||||||
req.socket.setTimeout(0)
|
req.socket.setTimeout(0)
|
||||||
req.on('close', () => {
|
req.on('close', () => {
|
||||||
|
@ -118,6 +120,7 @@ const handleStartServer = async(port: number, ip: string) => new Promise<void>((
|
||||||
case '/lyric':
|
case '/lyric':
|
||||||
code = 200
|
code = 200
|
||||||
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
|
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
|
||||||
|
res.setHeader('Access-Control-Allow-Origin', '*')
|
||||||
msg = global.lx.player_status.lyric
|
msg = global.lx.player_status.lyric
|
||||||
break
|
break
|
||||||
case '/subscribe-player-status':
|
case '/subscribe-player-status':
|
||||||
|
|
Loading…
Reference in New Issue