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:
@@ -12,6 +12,7 @@ import type { Task, TaskStep, User } from '@/types/database';
|
||||
import { CheckSquare, Clock, Calendar, AlertTriangle, User as UserIcon, Plus } from 'lucide-react';
|
||||
import { TaskEditDialog } from '@/components/task-edit-dialog';
|
||||
import { toast } from 'sonner';
|
||||
import { fetchApi } from '@/lib/api-client';
|
||||
|
||||
interface TaskWithRelations extends Task {
|
||||
steps: TaskStep[];
|
||||
@@ -41,7 +42,7 @@ export default function MyTasksPage() {
|
||||
? '/api/tasks'
|
||||
: `/api/tasks?user_id=${currentUser?.id}&include_help=true`;
|
||||
|
||||
const res = await fetch(url);
|
||||
const res = await fetchApi(url);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
// Enrich with owner info locally since API doesn't join
|
||||
@@ -61,7 +62,7 @@ export default function MyTasksPage() {
|
||||
const fetchHelpSteps = async () => {
|
||||
if (!currentUser?.id || currentUser.role === 'owner') return;
|
||||
try {
|
||||
const res = await fetch(`/api/task-steps?help_requested_to_user_id=${currentUser.id}`);
|
||||
const res = await fetchApi(`/api/task-steps?help_requested_to_user_id=${currentUser.id}`);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
setHelpSteps(data);
|
||||
@@ -80,7 +81,7 @@ export default function MyTasksPage() {
|
||||
|
||||
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