Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 525620b0f8 | |||
| ebc8d687d0 |
@@ -8,7 +8,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
from flask import jsonify
|
from flask import jsonify, request
|
||||||
from utils import log_message
|
from utils import log_message
|
||||||
from config import PROJECTS_FILE
|
from config import PROJECTS_FILE
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ def register_discovery_routes(app):
|
|||||||
@app.route('/api/discovery/services')
|
@app.route('/api/discovery/services')
|
||||||
def api_discovery_services():
|
def api_discovery_services():
|
||||||
"""扫描本机未注册的新服务"""
|
"""扫描本机未注册的新服务"""
|
||||||
# 1. 获取已知端口
|
# 1. 收集已知端口
|
||||||
known_ports = set()
|
known_ports = set()
|
||||||
try:
|
try:
|
||||||
with open(PROJECTS_FILE, 'r', encoding='utf-8') as f:
|
with open(PROJECTS_FILE, 'r', encoding='utf-8') as f:
|
||||||
@@ -179,7 +179,16 @@ def register_discovery_routes(app):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# 2. 获取 Docker 容器端口
|
# 2. 前端传入的额外排除端口(自定义服务等)
|
||||||
|
exclude_str = request.args.get('exclude_ports', '')
|
||||||
|
if exclude_str:
|
||||||
|
try:
|
||||||
|
for p in exclude_str.split(','):
|
||||||
|
known_ports.add(int(p.strip()))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 3. 获取 Docker 容器端口
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
['docker', 'ps', '--format', '{{.Ports}}'],
|
['docker', 'ps', '--format', '{{.Ports}}'],
|
||||||
|
|||||||
@@ -2238,6 +2238,7 @@
|
|||||||
const newService = {
|
const newService = {
|
||||||
id: 'custom_' + Date.now(),
|
id: 'custom_' + Date.now(),
|
||||||
name: name,
|
name: name,
|
||||||
|
port: port || '',
|
||||||
url: mainUrl,
|
url: mainUrl,
|
||||||
admin_url: adminUrl || null,
|
admin_url: adminUrl || null,
|
||||||
description: desc || '自定义外部服务',
|
description: desc || '自定义外部服务',
|
||||||
@@ -2886,7 +2887,12 @@
|
|||||||
list.innerHTML = '<div class="text-gray-400 text-xs text-center py-2"><i class="ri-loader-4-line animate-spin"></i> 扫描中...</div>';
|
list.innerHTML = '<div class="text-gray-400 text-xs text-center py-2"><i class="ri-loader-4-line animate-spin"></i> 扫描中...</div>';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/discovery/services');
|
// 收集前端已注册的自定义服务端口,传给后端排除
|
||||||
|
const customServices = getCustomServices();
|
||||||
|
const customPorts = customServices.map(s => parseInt(s.port)).filter(p => !isNaN(p));
|
||||||
|
const excludeParam = customPorts.length > 0 ? `?exclude_ports=${customPorts.join(',')}` : '';
|
||||||
|
|
||||||
|
const res = await fetch(`/api/discovery/services${excludeParam}`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const services = data.services || [];
|
const services = data.services || [];
|
||||||
document.getElementById('discoveryCount').textContent = `发现 ${services.length} 个`;
|
document.getElementById('discoveryCount').textContent = `发现 ${services.length} 个`;
|
||||||
|
|||||||
Reference in New Issue
Block a user