feat: 添加生产环境配置,重构 API 请求,更新部署脚本和配置

This commit is contained in:
richarjiang
2026-03-15 23:00:51 +08:00
parent 3c35f1982f
commit 441cc8dd48
14 changed files with 131 additions and 20 deletions

View File

@@ -8,6 +8,7 @@ import { UserDialog } from '@/components/users/user-dialog'
import { Spinner } from '@/components/ui/spinner'
import { User, UserFormData } from '@/types'
import { Plus, Pencil, Trash2 } from 'lucide-react'
import { apiFetch } from '@/lib/api'
export default function UsersPage() {
const queryClient = useQueryClient()
@@ -19,7 +20,7 @@ export default function UsersPage() {
const { data: users, isLoading, error } = useQuery<User[]>({
queryKey: ['users'],
queryFn: async () => {
const res = await fetch('/api/users')
const res = await apiFetch('/api/users')
if (!res.ok) throw new Error('Failed to fetch users')
return res.json()
},
@@ -28,7 +29,7 @@ export default function UsersPage() {
// Create user mutation
const createMutation = useMutation({
mutationFn: async (data: UserFormData) => {
const res = await fetch('/api/users', {
const res = await apiFetch('/api/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
@@ -47,7 +48,7 @@ export default function UsersPage() {
// Update user mutation
const updateMutation = useMutation({
mutationFn: async ({ id, data }: { id: string; data: UserFormData }) => {
const res = await fetch('/api/users', {
const res = await apiFetch('/api/users', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id, ...data }),
@@ -66,7 +67,7 @@ export default function UsersPage() {
// Delete user mutation
const deleteMutation = useMutation({
mutationFn: async (id: string) => {
const res = await fetch(`/api/users?id=${id}`, {
const res = await apiFetch(`/api/users?id=${id}`, {
method: 'DELETE',
})
if (!res.ok) {