添加开发API允许局域网访问选项(#1828)

This commit is contained in:
lyswhut
2024-04-01 22:44:34 +08:00
parent 703327ed41
commit cd7d5ed665
10 changed files with 31 additions and 11 deletions
+3 -3
View File
@@ -41,7 +41,7 @@ const handleSubscribePlayerStatus = (req: http.IncomingMessage, res: http.Server
}
}
const handleStartServer = async(port = 9000, ip = '127.0.0.1') => new Promise<void>((resolve, reject) => {
const handleStartServer = async(port: number, ip: string) => new Promise<void>((resolve, reject) => {
httpServer = http.createServer((req, res): void => {
const [endUrl, query] = `/${req.url?.split('/').at(-1) ?? ''}`.split('?')
let code
@@ -197,9 +197,9 @@ export const stopServer = async() => {
})
return status
}
export const startServer = async(port: number) => {
export const startServer = async(port: number, bindLan: boolean) => {
if (status.status) await handleStopServer()
await handleStartServer(port).then(() => {
await handleStartServer(port, bindLan ? '0.0.0.0' : '127.0.0.1').then(() => {
status.status = true
status.message = ''
status.address = `http://localhost${port == 80 ? '' : ':' + port}`
@@ -11,7 +11,7 @@ export default () => {
mainHandle<LX.OpenAPI.Actions, any>(WIN_MAIN_RENDERER_EVENT_NAME.open_api_action, async({ params: data }) => {
switch (data.action) {
case 'enable':
return data.data.enable ? await startServer(parseInt(data.data.port)) : await stopServer()
return data.data.enable ? await startServer(parseInt(data.data.port), data.data.bindLan) : await stopServer()
case 'status': return getStatus()
}
})