mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 00:21:56 +08:00
- 更新 docker-compose.yml 文件,使用端口 3336 - 修改 Dockerfile 以暴露端口 3336 - 重构 main.go 以支持新的路由和管理端点 - 在 auth.go 中实现健壮的身份验证中间件 - 通过加强错误检查来改进指标处理。 - 添加用于安全类型转换的实用函数 - 引入请求ID生成功能,以便更好地进行追踪。
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
async function login() {
|
|
const password = document.getElementById('password').value;
|
|
|
|
try {
|
|
const response = await fetch('/metrics/auth', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ password })
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('登录失败');
|
|
}
|
|
|
|
const data = await response.json();
|
|
localStorage.setItem('token', data.token);
|
|
window.location.href = '/metrics/dashboard';
|
|
} catch (error) {
|
|
showMessage(error.message, true);
|
|
}
|
|
}
|
|
|
|
function showMessage(msg, isError = false) {
|
|
const msgDiv = document.getElementById('message');
|
|
msgDiv.textContent = msg;
|
|
msgDiv.className = isError ? 'error' : 'success';
|
|
msgDiv.style.display = 'block';
|
|
setTimeout(() => {
|
|
msgDiv.style.display = 'none';
|
|
}, 5000);
|
|
}
|
|
|
|
// 添加回车键监听
|
|
document.getElementById('password').addEventListener('keypress', function(e) {
|
|
if (e.key === 'Enter') {
|
|
login();
|
|
}
|
|
});
|