forked from wangziqi/gongxue-base
feat(task1): restructure directories for turborepo monorepo
- Move backend/ to apps/server/ via git mv - Move frontend/ to apps/admin/ via git mv - Create packages/typescript-config/ with base, nestjs, and react-vite presets
This commit is contained in:
9
apps/server/src/common/request-utils.ts
Normal file
9
apps/server/src/common/request-utils.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* 从请求对象中提取客户端 IP 和 UserAgent
|
||||
*/
|
||||
export function extractRequestInfo(req: any): { ipAddress: string; userAgent: string } {
|
||||
const forwarded = req.headers?.['x-forwarded-for'] || req.headers?.['x-real-ip'] || req.connection?.remoteAddress || '';
|
||||
const ipAddress = String(forwarded).split(',')[0].trim() || 'unknown';
|
||||
const userAgent = (req.headers?.['user-agent'] || '').substring(0, 500);
|
||||
return { ipAddress, userAgent };
|
||||
}
|
||||
Reference in New Issue
Block a user