fix: fix /api/proxy-fetch transfer Authorization header

This commit is contained in:
purocean
2024-07-25 10:59:41 +08:00
parent fecb9e5a23
commit 54a6728f4e
2 changed files with 2 additions and 4 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ const noCache = (ctx: any) => {
}
const checkPermission = (ctx: any, next: any) => {
const token = ctx.query._token || (ctx.headers['x-yn-authorization'] || ctx.headers.authorization || '').replace('Bearer ', '')
const token = ctx.query._token || (ctx.headers['x-yn-authorization'] ?? (ctx.headers.authorization || '')).replace('Bearer', '').trim()
if (ctx.req._protocol || (!token && isLocalhost(ctx.request.ip))) {
ctx.req.jwt = { role: 'admin' }
+1 -3
View File
@@ -73,9 +73,7 @@ export async function proxyFetch (url: string, init?: Omit<RequestInit, 'body'>
init.body = JSON.stringify(init.body)
}
if (JWT_TOKEN) {
init.headers = { ...init.headers, 'x-yn-authorization': 'Bearer ' + JWT_TOKEN }
}
init.headers = { ...init.headers, 'x-yn-authorization': 'Bearer ' + JWT_TOKEN }
const res: Response = await fetch(`/api/proxy-fetch/${url}`, init)