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:
@@ -35,6 +35,7 @@ import {
|
||||
User as UserIcon,
|
||||
} from 'lucide-react';
|
||||
import { TaskEditDialog } from '@/components/task-edit-dialog';
|
||||
import { fetchApi } from '@/lib/api-client';
|
||||
|
||||
interface ProjectWithRelations extends Project {
|
||||
owner: User | null;
|
||||
@@ -100,10 +101,10 @@ export default function ProjectDetailPage({ projectId }: { projectId: string })
|
||||
const fetchData = useCallback(async () => {
|
||||
try {
|
||||
const [projectRes, objectivesRes, krsRes, tasksRes] = await Promise.all([
|
||||
fetch(`/api/projects/${projectId}`),
|
||||
fetch(`/api/objectives?project_id=${projectId}`),
|
||||
fetch(`/api/krs?project_id=${projectId}`),
|
||||
fetch(`/api/tasks?project_id=${projectId}`),
|
||||
fetchApi(`/api/projects/${projectId}`),
|
||||
fetchApi(`/api/objectives?project_id=${projectId}`),
|
||||
fetchApi(`/api/krs?project_id=${projectId}`),
|
||||
fetchApi(`/api/tasks?project_id=${projectId}`),
|
||||
]);
|
||||
|
||||
if (projectRes.status === 403) {
|
||||
@@ -156,7 +157,7 @@ export default function ProjectDetailPage({ projectId }: { projectId: string })
|
||||
const handleDeleteProject = async () => {
|
||||
setIsDeleting(true);
|
||||
try {
|
||||
const res = await fetch(`/api/projects/${projectId}`, { method: 'DELETE' });
|
||||
const res = await fetchApi(`/api/projects/${projectId}`, { method: 'DELETE' });
|
||||
if (!res.ok) throw new Error('删除失败');
|
||||
toast.success('项目已删除');
|
||||
router.push('/projects');
|
||||
@@ -172,7 +173,7 @@ export default function ProjectDetailPage({ projectId }: { projectId: string })
|
||||
setIsEditing(true);
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/projects/${projectId}`, {
|
||||
const res = await fetchApi(`/api/projects/${projectId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(editForm),
|
||||
@@ -199,7 +200,7 @@ export default function ProjectDetailPage({ projectId }: { projectId: string })
|
||||
if (!deleteObjectiveId) return;
|
||||
setIsDeletingObjective(true);
|
||||
try {
|
||||
const res = await fetch(`/api/objectives/${deleteObjectiveId}`, { method: 'DELETE' });
|
||||
const res = await fetchApi(`/api/objectives/${deleteObjectiveId}`, { method: 'DELETE' });
|
||||
if (!res.ok) throw new Error('删除失败');
|
||||
toast.success('目标已删除');
|
||||
fetchData();
|
||||
@@ -220,7 +221,7 @@ export default function ProjectDetailPage({ projectId }: { projectId: string })
|
||||
const formData = new FormData(e.currentTarget);
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/objectives/${editingObjective.id}`, {
|
||||
const res = await fetchApi(`/api/objectives/${editingObjective.id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
@@ -246,7 +247,7 @@ export default function ProjectDetailPage({ projectId }: { projectId: string })
|
||||
|
||||
const handleTaskStatusChange = async (taskId: string, newStatus: string) => {
|
||||
try {
|
||||
const res = await fetch(`/api/tasks/${taskId}`, {
|
||||
const res = await fetchApi(`/api/tasks/${taskId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ status: newStatus }),
|
||||
|
||||
Reference in New Issue
Block a user