mirror of
https://github.com/woodchen-ink/nezha-dash-v1.git
synced 2025-07-18 17:41:56 +08:00
chore: Update .gitignore to include Tencent Cloud EdgeOne files
This commit is contained in:
parent
7f29e94d15
commit
4522661879
7
.gitignore
vendored
7
.gitignore
vendored
@ -24,3 +24,10 @@ dev-dist
|
|||||||
*.njsproj
|
*.njsproj
|
||||||
*.sln
|
*.sln
|
||||||
*.sw?
|
*.sw?
|
||||||
|
|
||||||
|
# Tencent Cloud EdgeOne
|
||||||
|
.env
|
||||||
|
.edgeone
|
||||||
|
.edgeone/*
|
||||||
|
.tef_dist/*
|
||||||
|
|
39
functions/api/index.js
Normal file
39
functions/api/index.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
export async function onRequest(context) {
|
||||||
|
const { request, env } = context;
|
||||||
|
|
||||||
|
// 获取原始URL并解析路径
|
||||||
|
const url = new URL(request.url);
|
||||||
|
const path = url.pathname;
|
||||||
|
|
||||||
|
// 确保环境变量存在
|
||||||
|
if (!env.API_BASEURL) {
|
||||||
|
return new Response('API_BASEURL environment variable is not set', { status: 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建目标URL
|
||||||
|
const targetURL = new URL(path, env.API_BASEURL);
|
||||||
|
|
||||||
|
// 保留原始查询参数
|
||||||
|
targetURL.search = url.search;
|
||||||
|
|
||||||
|
// 创建新的请求
|
||||||
|
const newRequest = new Request(targetURL, {
|
||||||
|
method: request.method,
|
||||||
|
headers: request.headers,
|
||||||
|
body: request.body,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 转发请求到目标服务器
|
||||||
|
const response = await fetch(newRequest);
|
||||||
|
|
||||||
|
// 创建新的响应对象,保留原始响应的状态和头部
|
||||||
|
return new Response(response.body, {
|
||||||
|
status: response.status,
|
||||||
|
statusText: response.statusText,
|
||||||
|
headers: response.headers,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return new Response(`Proxy error: ${error.message}`, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user