feat: 添加 API 客户端以处理 basePath 并更新所有 fetch 调用
移除 next.config.js 中的 standalone 输出配置,添加 lib/api-client.ts 封装 fetch 请求, 自动为所有 API 调用添加配置的 basePath。更新所有页面和组件中的 fetch 调用以使用新的 fetchApi 函数, 确保在部署到子路径时 API 请求能正确工作。同时调整 tsconfig.json 的格式并修复项目创建时的字段名。
This commit is contained in:
@@ -28,6 +28,7 @@ import {
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog';
|
||||
import { fetchApi } from '@/lib/api-client';
|
||||
|
||||
const userSchema = z.object({
|
||||
name: z.string().min(1, '名称不能为空'),
|
||||
@@ -81,7 +82,7 @@ export default function AdminUsersPage() {
|
||||
password: values.password ? values.password : undefined,
|
||||
};
|
||||
|
||||
const res = await fetch(url, {
|
||||
const res = await fetchApi(url, {
|
||||
method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
@@ -124,7 +125,7 @@ export default function AdminUsersPage() {
|
||||
if (!deleteUserId) return;
|
||||
setIsDeleting(true);
|
||||
try {
|
||||
const res = await fetch(`/api/users/${deleteUserId}`, { method: 'DELETE' });
|
||||
const res = await fetchApi(`/api/users/${deleteUserId}`, { method: 'DELETE' });
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) throw new Error(data?.error || '删除失败');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user