This commit is contained in:
2025-03-25 00:38:41 +08:00
parent cb490470c1
commit 64c70ce527
14 changed files with 261 additions and 73 deletions

View File

@@ -12,6 +12,7 @@ export const createCookie = (token: any, ctx: any) => {
if (!domain) {
return;
}
//TODO, 获取访问的 hostname 如果访问的和 domain 的不一致也创建cookie
const browser = ctx.req.headers['user-agent'];
const isBrowser = browser.includes('Mozilla'); // 浏览器
if (isBrowser && ctx.res.cookie) {
@@ -50,11 +51,21 @@ export type ReqHeaders = {
cookie: string; // 饼干
};
export const getSomeInfoFromReq = (ctx: any) => {
const headers = ctx.req.headers as ReqHeaders;
const userAgent = headers['user-agent'];
const host = headers['host'];
const ip = headers['x-forwarded-for'] || ctx.req.connection.remoteAddress;
console.log('req headers', headers);
const headers = ctx.req?.headers as ReqHeaders;
if (!headers) {
console.log('no req headers', ctx.req);
return {
'user-agent': '',
browser: '',
isBrowser: false,
host: '',
ip: '',
headers: {},
};
}
const userAgent = headers?.['user-agent'] || '';
const host = headers?.['host'];
const ip = headers?.['x-forwarded-for'] || ctx.req?.connection?.remoteAddress;
return {
'user-agent': userAgent,
browser: userAgent,