本地开发反向代理

This commit is contained in:
2025-07-10 16:57:54 +08:00
parent a7370d4e8c
commit d1a47297bf
7 changed files with 86 additions and 87 deletions
+1 -1
View File
@@ -564,7 +564,7 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
// 调用 Java 接口
const javaResponse = await fetch(
`${process.env.NEXT_PUBLIC_BASE_API_URL}/api/conversation/feedback`,
`/dev-api/api/conversation/feedback`,
{
method: "POST",
headers: {
+1 -1
View File
@@ -199,7 +199,7 @@ const ChatWithHistoryWrapWithCheckToken: FC<ChatWithHistoryWrapProps> = ({
if (!accessToken) {
router.replace("/login");
} else {
fetch(`${process.env.NEXT_PUBLIC_BASE_API_URL}/getInfo`, {
fetch(`/dev-api/getInfo`, {
method: "GET",
headers: {
Authorization: `Bearer ${accessToken}`,
+70 -70
View File
@@ -1,70 +1,70 @@
'use client'
import { useState } from 'react'
import { useRouter } from 'next/navigation'
export default function LoginPage() {
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState('')
const router = useRouter()
const [loading, setLoading] = useState(false) // 新增加载状态
const handleLogin = async (e: React.FormEvent) => {
e.preventDefault()
setLoading(true) // 开始加载
fetch(`${process.env.NEXT_PUBLIC_BASE_API_URL}/login`, {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password }),
}).then(res => res.json()).then(data => {
if (data.code === 200) {
localStorage.setItem('token', data.token)
document.cookie = `username=${username}; path=/` // 新增cookie设置
router.push('/')
} else {
setError('登录失败,请检查凭证')
setLoading(false)
}
})
}
return (
<div className="min-h-screen bg-gray-100 flex items-center justify-center">
<div className="bg-white p-8 rounded-lg shadow-md w-96">
<h1 className="text-2xl font-bold mb-6 text-center">Login</h1>
<form onSubmit={handleLogin}>
<div className="mb-4">
<label className="block text-sm font-medium mb-1">Username</label>
<input
type="text"
className="w-full px-3 py-2 border rounded-md"
value={username}
onChange={e => setUsername(e.target.value)}
required
/>
</div>
<div className="mb-6">
<label className="block text-sm font-medium mb-1">Password</label>
<input
type="password"
className="w-full px-3 py-2 border rounded-md"
value={password}
onChange={e => setPassword(e.target.value)}
required
/>
</div>
{error && <p className="text-red-500 text-sm mb-4">{error}</p>}
<button
type="submit"
disabled={loading} // 禁用按钮
className={`w-full bg-blue-500 text-white py-2 px-4 rounded-md transition-colors ${!loading && 'hover:bg-blue-600'}`}
>
{loading ? 'Loading...' : 'Sign In'}
</button>
</form>
</div>
</div>
)
}
'use client'
import { useState } from 'react'
import { useRouter } from 'next/navigation'
export default function LoginPage() {
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState('')
const router = useRouter()
const [loading, setLoading] = useState(false) // 新增加载状态
const handleLogin = async (e: React.FormEvent) => {
e.preventDefault()
setLoading(true) // 开始加载
fetch(`/dev-api/login`, {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password }),
}).then(res => res.json()).then(data => {
if (data.code === 200) {
localStorage.setItem('token', data.token)
document.cookie = `username=${username}; path=/` // 新增cookie设置
router.push('/')
} else {
setError('登录失败,请检查凭证')
setLoading(false)
}
})
}
return (
<div className="min-h-screen bg-gray-100 flex items-center justify-center">
<div className="bg-white p-8 rounded-lg shadow-md w-96">
<h1 className="text-2xl font-bold mb-6 text-center">Login</h1>
<form onSubmit={handleLogin}>
<div className="mb-4">
<label className="block text-sm font-medium mb-1">Username</label>
<input
type="text"
className="w-full px-3 py-2 border rounded-md"
value={username}
onChange={e => setUsername(e.target.value)}
required
/>
</div>
<div className="mb-6">
<label className="block text-sm font-medium mb-1">Password</label>
<input
type="password"
className="w-full px-3 py-2 border rounded-md"
value={password}
onChange={e => setPassword(e.target.value)}
required
/>
</div>
{error && <p className="text-red-500 text-sm mb-4">{error}</p>}
<button
type="submit"
disabled={loading} // 禁用按钮
className={`w-full bg-blue-500 text-white py-2 px-4 rounded-md transition-colors ${!loading && 'hover:bg-blue-600'}`}
>
{loading ? 'Loading...' : 'Sign In'}
</button>
</form>
</div>
</div>
)
}
+6 -8
View File
@@ -1,11 +1,13 @@
@import "preflight.css";
@tailwind base;
@tailwind components;
@import '../../themes/light.css';
@import '../../themes/dark.css';
@import "../../themes/manual-light.css";
@import "../../themes/manual-dark.css";
@import "../components/base/button/index.css";
@import "../components/base/action-button/index.css";
@import "../components/base/modal/index.css";
@tailwind base;
@tailwind components;
html {
color-scheme: light;
@@ -680,8 +682,4 @@ button:focus-within {
display: none;
}
@import "../components/base/button/index.css";
@import "../components/base/action-button/index.css";
@import "../components/base/modal/index.css";
@tailwind utilities;
@tailwind utilities;