diff --git a/assistant/src/module/http-token.ts b/assistant/src/module/http-token.ts index 27b7ea7..6f4f734 100644 --- a/assistant/src/module/http-token.ts +++ b/assistant/src/module/http-token.ts @@ -15,14 +15,9 @@ const cookie = { return cookies; } } -export const getToken = async (req: http.IncomingMessage, res: http.ServerResponse) => { +export const getToken = async (req: http.IncomingMessage) => { let token = (req.headers?.['authorization'] as string) || (req.headers?.['Authorization'] as string) || ''; const url = new URL(req.url || '', 'http://localhost'); - const resNoPermission = () => { - res.statusCode = 401; - res.end(error('Invalid authorization')); - return { tokenUser: null, token: null }; - }; if (!token) { token = url.searchParams.get('token') || ''; } @@ -30,9 +25,6 @@ export const getToken = async (req: http.IncomingMessage, res: http.ServerRespon const parsedCookies = cookie.parse(req.headers.cookie || ''); token = parsedCookies.token || ''; } - if (!token) { - return resNoPermission(); - } if (token) { token = token.replace('Bearer ', ''); } diff --git a/assistant/src/server.ts b/assistant/src/server.ts index 52338f7..8102c5c 100644 --- a/assistant/src/server.ts +++ b/assistant/src/server.ts @@ -10,7 +10,7 @@ import chalk from 'chalk'; import { AssistantApp } from './lib.ts'; import { getBunPath } from './module/get-bun-path.ts'; import { qwenAsr } from './services/asr/qwen-asr.ts'; -export const runServer = async (port: number = 51015, listenPath = '127.0.0.1') => { +export const runServer = async (port: number = 51515, listenPath = '127.0.0.1') => { let _port: number | undefined; if (port) { _port = await getPort({ port }); @@ -21,7 +21,7 @@ export const runServer = async (port: number = 51015, listenPath = '127.0.0.1') } if (!_port) { // 检车端口可用性 - const isPortAvailable = await getPort({ port: portNumbers(51015, 52000) }); + const isPortAvailable = await getPort({ port: portNumbers(51515, 52000) }); if (!isPortAvailable) { console.log(`Port ${isPortAvailable} is not available`); process.exit(1); diff --git a/assistant/src/services/proxy/proxy-page-index.ts b/assistant/src/services/proxy/proxy-page-index.ts index 100a048..81ed1b2 100644 --- a/assistant/src/services/proxy/proxy-page-index.ts +++ b/assistant/src/services/proxy/proxy-page-index.ts @@ -34,7 +34,7 @@ const authFilter = async (req: http.IncomingMessage, res: http.ServerResponse) = return false; } // 放开首页 - if (pathname.startsWith('/root/home')) { + if (pathname.startsWith('/root/home') || pathname === '/root/cli') { return false; } // 放开api, 以 /api, /v1, /client, /serve 开头的请求 @@ -47,8 +47,11 @@ const authFilter = async (req: http.IncomingMessage, res: http.ServerResponse) = if (share === 'public') { return false; } - const { token } = await getToken(req, res) + const { token } = await getToken(req) if (!token) { + // no token 转到登录页面 + res.writeHead(302, { Location: `/root/home/` }); + res.end(); return false; } const tokenUser = await getTokenUserCache(token);