新增 .dockerignore,添加 X-Forwarded-For 头以正确提供客户端 IP 信息
This commit is contained in:
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@@ -0,0 +1,6 @@
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
node_modules/
|
||||
.next/
|
||||
.env
|
||||
@@ -1,5 +1,7 @@
|
||||
## TODO
|
||||
|
||||
使用 pure js 的包代替 canvas,加快编译速度
|
||||
|
||||
重新设计验证逻辑,通过全局 cache 优化请求效率,使用服务端组件实现验证
|
||||
|
||||
提取后刷新提取页套餐可用余量
|
||||
|
||||
@@ -58,7 +58,8 @@
|
||||
"packageManager": "pnpm@10.5.2+sha512.da9dc28cd3ff40d0592188235ab25d3202add8a207afbedc682220e4a0029ffbff4562102b9e6e46b4e3f9e8bd53e6d05de48544b0c57d4b0179e22c76d1199b",
|
||||
"pnpm": {
|
||||
"onlyBuiltDependencies": [
|
||||
"canvas"
|
||||
"canvas",
|
||||
"sharp"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use server'
|
||||
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'
|
||||
|
||||
// OAuth令牌缓存
|
||||
@@ -176,24 +176,29 @@ async function callByUser<R = undefined>(
|
||||
): Promise<ApiResponse<R>> {
|
||||
try {
|
||||
let token = await getUserToken()
|
||||
|
||||
const header = await headers()
|
||||
|
||||
// 获取客户端 IP
|
||||
const clientIp = header.get('x-forwarded-for')
|
||||
|
||||
// 发送请求
|
||||
let response: Response
|
||||
const requestOptions = {
|
||||
const request = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
} as Record<string, string>,
|
||||
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) {
|
||||
token = await getUserToken(true)
|
||||
requestOptions.headers['Authorization'] = `Bearer ${token}`
|
||||
response = await fetch(`${API_BASE_URL}${endpoint}`, requestOptions)
|
||||
request.headers['Authorization'] = `Bearer ${token}`
|
||||
response = await fetch(`${API_BASE_URL}${endpoint}`, request)
|
||||
}
|
||||
|
||||
// 检查响应状态
|
||||
|
||||
Reference in New Issue
Block a user