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:
@@ -48,6 +48,7 @@ import {
|
||||
} from 'lucide-react';
|
||||
|
||||
import { getErrorMessage } from '@/lib/error-utils';
|
||||
import { fetchApi } from '@/lib/api-client';
|
||||
|
||||
interface KRWithRelations extends KR {
|
||||
owner: User | null;
|
||||
@@ -90,9 +91,9 @@ export default function KRDetailPage({ krId }: { krId: string }) {
|
||||
const fetchData = useCallback(async () => {
|
||||
try {
|
||||
const [krRes, checkinsRes, tasksRes] = await Promise.all([
|
||||
fetch(`/api/krs/${krId}`),
|
||||
fetch(`/api/checkins?kr_id=${krId}`),
|
||||
fetch(`/api/tasks?kr_id=${krId}`),
|
||||
fetchApi(`/api/krs/${krId}`),
|
||||
fetchApi(`/api/checkins?kr_id=${krId}`),
|
||||
fetchApi(`/api/tasks?kr_id=${krId}`),
|
||||
]);
|
||||
|
||||
if (krRes.status === 403) {
|
||||
@@ -159,7 +160,7 @@ export default function KRDetailPage({ krId }: { krId: string }) {
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
const res = await fetch('/api/checkins', {
|
||||
const res = await fetchApi('/api/checkins', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
@@ -192,7 +193,7 @@ export default function KRDetailPage({ krId }: { krId: string }) {
|
||||
if (!kr) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/krs/${kr.id}`, {
|
||||
const res = await fetchApi(`/api/krs/${kr.id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
@@ -214,7 +215,7 @@ export default function KRDetailPage({ krId }: { krId: string }) {
|
||||
if (!kr) return;
|
||||
setIsDeleting(true);
|
||||
try {
|
||||
const res = await fetch(`/api/krs/${kr.id}`, { method: 'DELETE' });
|
||||
const res = await fetchApi(`/api/krs/${kr.id}`, { method: 'DELETE' });
|
||||
if (!res.ok) throw new Error('删除失败');
|
||||
toast.success('KR 已删除');
|
||||
router.push(`/projects/${kr.project_id}`);
|
||||
@@ -233,7 +234,7 @@ export default function KRDetailPage({ krId }: { krId: string }) {
|
||||
const formData = new FormData(e.currentTarget);
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/krs/${kr.id}`, {
|
||||
const res = await fetchApi(`/api/krs/${kr.id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
@@ -293,7 +294,7 @@ export default function KRDetailPage({ krId }: { krId: 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