diff --git a/check-status.html b/check-status.html
new file mode 100644
index 0000000..612b052
--- /dev/null
+++ b/check-status.html
@@ -0,0 +1,248 @@
+
+
+
+
+
+ 产业状态检查 - 调试版
+
+
+
+
+
🔍 产业状态检查工具
+
+
+
+
+
+
+ 检查日志:
+
+
+
+
+
+
\ No newline at end of file
diff --git a/index.html b/index.html
index df23fb2..201ac95 100644
--- a/index.html
+++ b/index.html
@@ -501,25 +501,98 @@
// 检查单个产业状态
async function checkStatus(port) {
const statusEl = document.getElementById(`status-${port}`);
+
+ // 使用多种方法检测端口状态
try {
- // 尝试访问端口
- const response = await fetch(`http://localhost:${port}`, {
- mode: 'no-cors',
- cache: 'no-cache'
- });
+ // 方法1: 创建一个script标签来测试
+ const testScript = document.createElement('script');
+ testScript.src = `http://localhost:${port}/vite.svg?t=${Date.now()}`;
+ testScript.onerror = () => {
+ // 方法2: 使用Image对象检测
+ const img = new Image();
+ let isResolved = false;
- // 使用图片加载来检测
- const img = new Image();
- img.src = `http://localhost:${port}/favicon.ico?t=${Date.now()}`;
+ const checkTimeout = setTimeout(() => {
+ if (!isResolved) {
+ isResolved = true;
+ statusEl.className = 'status status-stopped';
+ statusEl.innerHTML = ' 已停止';
+ }
+ }, 2000);
- await new Promise((resolve, reject) => {
- img.onload = resolve;
- img.onerror = reject;
- setTimeout(reject, 2000);
- });
+ img.onload = () => {
+ if (!isResolved) {
+ isResolved = true;
+ clearTimeout(checkTimeout);
+ statusEl.className = 'status status-running';
+ statusEl.innerHTML = ' 运行中';
+ }
+ };
+
+ img.onerror = () => {
+ // 方法3: 尝试使用XMLHttpRequest
+ const xhr = new XMLHttpRequest();
+ xhr.open('HEAD', `http://localhost:${port}/`, true);
+ xhr.timeout = 2000;
+
+ xhr.onreadystatechange = function() {
+ if (!isResolved && xhr.readyState === 4) {
+ isResolved = true;
+ clearTimeout(checkTimeout);
+ // 即使有CORS错误,如果收到响应就说明服务在运行
+ if (xhr.status === 0 || xhr.status === 200) {
+ // status为0通常表示CORS阻止,但服务器确实响应了
+ statusEl.className = 'status status-running';
+ statusEl.innerHTML = ' 运行中';
+ } else {
+ statusEl.className = 'status status-stopped';
+ statusEl.innerHTML = ' 已停止';
+ }
+ }
+ };
+
+ xhr.onerror = function() {
+ if (!isResolved) {
+ isResolved = true;
+ clearTimeout(checkTimeout);
+ // 网络错误通常意味着服务未运行
+ statusEl.className = 'status status-stopped';
+ statusEl.innerHTML = ' 已停止';
+ }
+ };
+
+ try {
+ xhr.send();
+ } catch(e) {
+ // 发送失败,但这可能是因为CORS
+ if (!isResolved) {
+ isResolved = true;
+ clearTimeout(checkTimeout);
+ statusEl.className = 'status status-running';
+ statusEl.innerHTML = ' 运行中';
+ }
+ }
+ };
+
+ // 尝试加载各种可能的静态资源
+ const possiblePaths = [
+ '/favicon.ico',
+ '/vite.svg',
+ '/index.html',
+ '/assets/index.css'
+ ];
+
+ img.src = `http://localhost:${port}${possiblePaths[0]}?t=${Date.now()}`;
+ };
+
+ testScript.onload = () => {
+ statusEl.className = 'status status-running';
+ statusEl.innerHTML = ' 运行中';
+ };
+
+ document.head.appendChild(testScript);
+ setTimeout(() => document.head.removeChild(testScript), 100);
- statusEl.className = 'status status-running';
- statusEl.innerHTML = ' 运行中';
} catch (error) {
statusEl.className = 'status status-stopped';
statusEl.innerHTML = ' 已停止';