新增 .dockerignore,添加 X-Forwarded-For 头以正确提供客户端 IP 信息

This commit is contained in:
2025-04-21 19:02:14 +08:00
parent 2b3f6768f0
commit 5b3de2b714
4 changed files with 24 additions and 10 deletions

6
.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
.idea/
.vscode/
node_modules/
.next/
.env

View File

@@ -1,5 +1,7 @@
## TODO ## TODO
使用 pure js 的包代替 canvas加快编译速度
重新设计验证逻辑,通过全局 cache 优化请求效率,使用服务端组件实现验证 重新设计验证逻辑,通过全局 cache 优化请求效率,使用服务端组件实现验证
提取后刷新提取页套餐可用余量 提取后刷新提取页套餐可用余量

View File

@@ -58,7 +58,8 @@
"packageManager": "pnpm@10.5.2+sha512.da9dc28cd3ff40d0592188235ab25d3202add8a207afbedc682220e4a0029ffbff4562102b9e6e46b4e3f9e8bd53e6d05de48544b0c57d4b0179e22c76d1199b", "packageManager": "pnpm@10.5.2+sha512.da9dc28cd3ff40d0592188235ab25d3202add8a207afbedc682220e4a0029ffbff4562102b9e6e46b4e3f9e8bd53e6d05de48544b0c57d4b0179e22c76d1199b",
"pnpm": { "pnpm": {
"onlyBuiltDependencies": [ "onlyBuiltDependencies": [
"canvas" "canvas",
"sharp"
] ]
} }
} }

View File

@@ -1,6 +1,6 @@
'use server' 'use server'
import {API_BASE_URL, CLIENT_ID, CLIENT_SECRET, ApiResponse, UnauthorizedError} from '@/lib/api' import {API_BASE_URL, CLIENT_ID, CLIENT_SECRET, ApiResponse, UnauthorizedError} from '@/lib/api'
import {cookies} from 'next/headers' import {cookies, headers} from 'next/headers'
import {redirect} from 'next/navigation' import {redirect} from 'next/navigation'
// OAuth令牌缓存 // OAuth令牌缓存
@@ -176,24 +176,29 @@ async function callByUser<R = undefined>(
): Promise<ApiResponse<R>> { ): Promise<ApiResponse<R>> {
try { try {
let token = await getUserToken() let token = await getUserToken()
const header = await headers()
// 获取客户端 IP
const clientIp = header.get('x-forwarded-for')
// 发送请求 // 发送请求
let response: Response const request = {
const requestOptions = {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`, 'Authorization': `Bearer ${token}`,
}, } as Record<string, string>,
body: data ? JSON.stringify(data) : undefined, body: data ? JSON.stringify(data) : undefined,
} }
if (clientIp) {
request.headers['X-Forwarded-For'] = clientIp
}
response = await fetch(`${API_BASE_URL}${endpoint}`, requestOptions) let response = await fetch(`${API_BASE_URL}${endpoint}`, request)
if (response.status === 401) { if (response.status === 401) {
token = await getUserToken(true) token = await getUserToken(true)
requestOptions.headers['Authorization'] = `Bearer ${token}` request.headers['Authorization'] = `Bearer ${token}`
response = await fetch(`${API_BASE_URL}${endpoint}`, requestOptions) response = await fetch(`${API_BASE_URL}${endpoint}`, request)
} }
// 检查响应状态 // 检查响应状态