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:
@@ -8,6 +8,7 @@ import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { toast } from 'sonner';
|
||||
import { useUser } from '@/components/user-context';
|
||||
import { fetchApi } from '@/lib/api-client';
|
||||
|
||||
const DEFAULT_USERNAME = 'baicaimiao';
|
||||
const DEFAULT_PASSWORD = 'baicaimiao123';
|
||||
@@ -29,7 +30,7 @@ export default function LoginPage() {
|
||||
e.preventDefault();
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
const res = await fetch('/api/auth/login', {
|
||||
const res = await fetchApi('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password }),
|
||||
|
||||
Reference in New Issue
Block a user