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生成功能,以便更好地进行追踪。
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
let editor = ace.edit("editor");
|
|
editor.setTheme("ace/theme/monokai");
|
|
editor.session.setMode("ace/mode/json");
|
|
editor.setOptions({
|
|
fontSize: "14px"
|
|
});
|
|
|
|
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);
|
|
}
|
|
|
|
async function loadConfig() {
|
|
try {
|
|
const response = await fetch('/metrics/config/get');
|
|
if (!response.ok) {
|
|
throw new Error('加载配置失败');
|
|
}
|
|
const config = await response.json();
|
|
editor.setValue(JSON.stringify(config, null, 2), -1);
|
|
showMessage('配置已加载');
|
|
} catch (error) {
|
|
showMessage(error.message, true);
|
|
}
|
|
}
|
|
|
|
async function saveConfig() {
|
|
try {
|
|
const config = JSON.parse(editor.getValue());
|
|
const response = await fetch('/metrics/config/save', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(config)
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const error = await response.text();
|
|
throw new Error(error);
|
|
}
|
|
|
|
const result = await response.json();
|
|
showMessage(result.message);
|
|
} catch (error) {
|
|
showMessage(error.message, true);
|
|
}
|
|
}
|
|
|
|
function formatJson() {
|
|
try {
|
|
const config = JSON.parse(editor.getValue());
|
|
editor.setValue(JSON.stringify(config, null, 2), -1);
|
|
showMessage('JSON已格式化');
|
|
} catch (error) {
|
|
showMessage('JSON格式错误: ' + error.message, true);
|
|
}
|
|
}
|
|
|
|
// 初始加载配置
|
|
loadConfig();
|