Files
comm-framework/ServerModule/target/classes/static/index.html
T
2026-05-07 15:54:43 +08:00

175 lines
5.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>通信探测</title>
<style>
body { font-family: sans-serif; margin: 1rem; }
button { margin-right: 0.5rem; margin-bottom: 0.5rem; }
pre { background: #f4f4f4; padding: 0.75rem; white-space: pre-wrap; }
</style>
</head>
<body>
<p>业务 TCP4 字节大端长度 + <code>CmdRpcEnvelope</code>)端口:<code id="tcpPort"></code>
三条路径示例请运行 <code>com.huangzj.server.demo.TcpPathsDemo</code>(需先起 CrossModule 再起 ServerModule)。</p>
<button type="button" id="btnHttp">验证 HTTP</button>
<button type="button" id="btnMongoNow">Mongo 立即保存</button>
<button type="button" id="btnMongoLater">Mongo 定时保存</button>
<button type="button" id="btnMongoRead">Mongo 读最新</button>
<button type="button" id="btnRedisSet">Redis 写入</button>
<button type="button" id="btnRedisGet">Redis 读取</button>
<button type="button" id="btnEventPub">事件发布</button>
<button type="button" id="btnEventRead">事件状态</button>
<button type="button" id="btnModInfo">模块注册与定时配置</button>
<button type="button" id="btnModTick">手动 tick 全部 GeneralModule</button>
<button type="button" id="btnModSave">全部模块 saveData</button>
<pre id="log"></pre>
<script>
const logEl = document.getElementById('log');
let playerId = 900001;
function log(msg) {
logEl.textContent += msg + '\n';
}
async function refreshEndpoints() {
try {
const tcp = await fetch('/api/config/client-tcp');
const tj = await tcp.json();
document.getElementById('tcpPort').textContent = String(tj.port);
const mi = await fetch('/api/demo/module/info');
const mj = await mi.json();
playerId = mj.playerId;
} catch (e) {
log('加载配置失败 ' + e);
}
}
document.getElementById('btnHttp').onclick = async () => {
try {
const r = await fetch('/api/ping');
const j = await r.json();
log('[HTTP] ' + JSON.stringify(j));
} catch (e) {
log('[HTTP] 失败: ' + e);
}
};
document.getElementById('btnMongoNow').onclick = async () => {
try {
await refreshEndpoints();
const body = { playerId: playerId, content: 'immediate-' + Date.now() };
const r = await fetch('/api/demo/mongo/save-immediate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
});
log('[Mongo立即] ' + await r.text());
} catch (e) {
log('[Mongo立即] ' + e);
}
};
document.getElementById('btnMongoLater').onclick = async () => {
try {
await refreshEndpoints();
const body = { playerId: playerId, content: 'scheduled-' + Date.now() };
const r = await fetch('/api/demo/mongo/save-scheduled', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
});
log('[Mongo定时标记] ' + r.status);
} catch (e) {
log('[Mongo定时] ' + e);
}
};
document.getElementById('btnMongoRead').onclick = async () => {
try {
await refreshEndpoints();
const r = await fetch('/api/demo/mongo/latest?playerId=' + encodeURIComponent(playerId));
log('[Mongo读] ' + await r.text());
} catch (e) {
log('[Mongo读] ' + e);
}
};
document.getElementById('btnRedisSet').onclick = async () => {
try {
const r = await fetch('/api/demo/redis/set', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key: 'demoKey', value: 'demoVal-' + Date.now() })
});
log('[Redis写] ' + r.status);
} catch (e) {
log('[Redis写] ' + e);
}
};
document.getElementById('btnRedisGet').onclick = async () => {
try {
const r = await fetch('/api/demo/redis/get?key=demoKey');
log('[Redis读] ' + await r.text());
} catch (e) {
log('[Redis读] ' + e);
}
};
document.getElementById('btnEventPub').onclick = async () => {
try {
const r = await fetch('/api/demo/event/publish', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ topic: 'demo', body: 'hello-' + Date.now() })
});
log('[事件发布] ' + r.status);
} catch (e) {
log('[事件发布] ' + e);
}
};
document.getElementById('btnEventRead').onclick = async () => {
try {
const r = await fetch('/api/demo/event/last');
log('[事件状态] ' + await r.text());
} catch (e) {
log('[事件状态] ' + e);
}
};
document.getElementById('btnModInfo').onclick = async () => {
try {
const r = await fetch('/api/demo/module/info');
log('[模块] ' + await r.text());
} catch (e) {
log('[模块] ' + e);
}
};
document.getElementById('btnModTick').onclick = async () => {
try {
const r = await fetch('/api/demo/module/tick', { method: 'POST' });
log('[模块tick] ' + await r.text());
} catch (e) {
log('[模块tick] ' + e);
}
};
document.getElementById('btnModSave').onclick = async () => {
try {
const r = await fetch('/api/demo/module/save', { method: 'POST' });
log('[模块save] ' + r.status);
} catch (e) {
log('[模块save] ' + e);
}
};
refreshEndpoints();
</script>
</body>
</html>