fix: 更新依赖项版本并优化远程应用连接逻辑
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { useKey } from '@kevisual/use-config';
|
||||
import http from 'node:http';
|
||||
import { IncomingMessage } from 'node:http';
|
||||
export const error = (msg: string, code = 500) => {
|
||||
return JSON.stringify({ code, message: msg });
|
||||
};
|
||||
@@ -16,7 +15,12 @@ const cookie = {
|
||||
return cookies;
|
||||
}
|
||||
}
|
||||
export const getToken = async (req: http.IncomingMessage) => {
|
||||
/**
|
||||
* 从请求中获取token,优先级:Authorization header > query parameter > cookie
|
||||
* @param req
|
||||
* @returns
|
||||
*/
|
||||
export const getToken = async (req: IncomingMessage) => {
|
||||
let token = (req.headers?.['authorization'] as string) || (req.headers?.['Authorization'] as string) || '';
|
||||
const url = new URL(req.url || '', 'http://localhost');
|
||||
if (!token) {
|
||||
@@ -31,9 +35,4 @@ export const getToken = async (req: http.IncomingMessage) => {
|
||||
}
|
||||
|
||||
return { token };
|
||||
};
|
||||
|
||||
export const getEnvToken = () => {
|
||||
const envTokne = useKey('KEVISUAL_TOKEN') || '';
|
||||
return envTokne;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user