temp
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user