fix(handler): 统一错误处理并替换Next.js重写为路由处理器
- 将所有handler中的Fail函数调用替换为FailError以统一错误处理 - 添加FailError函数实现统一的错误日志记录和响应格式 - 移除Next.js配置中的rewrites并实现统一的API路由代理处理器 - 新增路由处理器支持长连接和大文件上传场景的代理转发 - 更新错误处理逻辑避免将内部错误详情暴露给前端用户
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import type { NextConfig } from "next";
|
||||
import { PHASE_DEVELOPMENT_SERVER } from "next/constants";
|
||||
import { loadEnvConfig } from "@next/env";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname, resolve } from "node:path";
|
||||
@@ -12,8 +11,6 @@ const localChangelog = readFileSync(resolve(webDir, "../CHANGELOG.md"), "utf8");
|
||||
|
||||
export default function nextConfig(phase: string): NextConfig {
|
||||
const isDev = phase === PHASE_DEVELOPMENT_SERVER;
|
||||
loadEnvConfig(resolve(webDir, ".."), isDev, undefined, true);
|
||||
const apiBaseUrl = process.env.API_BASE_URL || "http://127.0.0.1:8080";
|
||||
const releases = parseChangelog(localChangelog);
|
||||
|
||||
return {
|
||||
@@ -25,8 +22,5 @@ export default function nextConfig(phase: string): NextConfig {
|
||||
NEXT_PUBLIC_APP_VERSION: localVersion,
|
||||
NEXT_PUBLIC_APP_RELEASES: JSON.stringify(releases),
|
||||
},
|
||||
async rewrites() {
|
||||
return [{ source: "/api/:path*", destination: `${apiBaseUrl}/api/:path*` }];
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user