// 系统信息: 当前访问者 IP 等 // 仅供「我」页展示, 需要登录后访问 import { Router } from 'express' import { authRequired } from '../middleware.js' const router = Router() router.use(authRequired) router.use((_req, res, next) => { res.set('Cache-Control', 'no-store') next() }) // 去掉 IPv4-mapped IPv6 前缀 (::ffff:1.2.3.4 → 1.2.3.4), 便于展示 function normalizeIp(ip) { const s = String(ip || '').trim() return s.startsWith('::ffff:') ? s.slice(7) : s } // GET /api/system/client-ip 服务器看到的当前访问 IP // 依赖 index.js 里的 trust proxy 设置解析 X-Forwarded-For (生产经 NPM 反代) router.get('/client-ip', (req, res) => { res.json({ ip: normalizeIp(req.ip || req.socket?.remoteAddress) }) }) export default router