refactor(web): Update API routes to use /admin prefix

- Modify fetch API calls in dashboard, login, and config pages
- Update routes to consistently use /admin/api/ endpoint
- Ensure uniform API route handling across frontend components
This commit is contained in:
wood chen 2025-02-15 11:56:03 +08:00
parent f758db3531
commit b5a6928a3a
5 changed files with 7 additions and 7 deletions

View File

@ -25,7 +25,7 @@ export default function ConfigPage() {
return return
} }
const response = await fetch("/api/config/get", { const response = await fetch("/admin/api/config/get", {
headers: { headers: {
'Authorization': `Bearer ${token}`, 'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json' 'Content-Type': 'application/json'
@ -68,7 +68,7 @@ export default function ConfigPage() {
return return
} }
const response = await fetch("/api/config/save", { const response = await fetch("/admin/api/config/save", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",

View File

@ -46,7 +46,7 @@ export default function DashboardLayout({
} }
// 验证 token 有效性 // 验证 token 有效性
fetch("/api/check-auth").catch(() => { fetch("/admin/api/check-auth").catch(() => {
localStorage.removeItem("token") localStorage.removeItem("token")
router.push("/login") router.push("/login")
}) })

View File

@ -47,7 +47,7 @@ export default function DashboardPage() {
return return
} }
const response = await fetch("/api/metrics", { const response = await fetch("/admin/api/metrics", {
headers: { headers: {
'Authorization': `Bearer ${token}` 'Authorization': `Bearer ${token}`
} }

View File

@ -18,7 +18,7 @@ export default function LoginPage() {
setLoading(true) setLoading(true)
try { try {
const response = await fetch("/api/auth", { const response = await fetch("/admin/api/auth", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded",
@ -34,7 +34,7 @@ export default function LoginPage() {
localStorage.setItem("token", data.token) localStorage.setItem("token", data.token)
// 验证token // 验证token
const verifyResponse = await fetch("/api/check-auth", { const verifyResponse = await fetch("/admin/api/check-auth", {
headers: { headers: {
'Authorization': `Bearer ${data.token}`, 'Authorization': `Bearer ${data.token}`,
}, },

View File

@ -12,7 +12,7 @@ export function Nav() {
const handleLogout = async () => { const handleLogout = async () => {
try { try {
const response = await fetch("/api/logout", { const response = await fetch("/admin/api/logout", {
method: "POST", method: "POST",
}) })