@@ -5,7 +5,7 @@ import type { ApiProduct, LinkedService, RestAPIItem, NacosMCPItem, APIGAIMCPIte
55import type { Gateway , NacosInstance } from '@/types/gateway'
66import { apiProductApi , gatewayApi , nacosApi } from '@/lib/api'
77import { getGatewayTypeLabel } from '@/lib/constant'
8- import { copyToClipboard } from '@/lib/utils'
8+ import { copyToClipboard , formatDomainWithPort } from '@/lib/utils'
99import * as yaml from 'js-yaml'
1010import { SwaggerUIWrapper } from './SwaggerUIWrapper'
1111
@@ -109,11 +109,12 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
109109 } , [ apiProduct , linkedService , selectedDomainIndex ] )
110110
111111 // 生成域名选项的函数
112- const getDomainOptions = ( domains : Array < { domain : string ; protocol : string ; networkType ?: string } > ) => {
112+ const getDomainOptions = ( domains : Array < { domain : string ; port ?: number ; protocol : string ; networkType ?: string } > ) => {
113113 return domains . map ( ( domain , index ) => {
114+ const formattedDomain = formatDomainWithPort ( domain . domain , domain . port , domain . protocol ) ;
114115 return {
115116 value : index ,
116- label : `${ domain . protocol } ://${ domain . domain } ` ,
117+ label : `${ domain . protocol } ://${ formattedDomain } ` ,
117118 domain : domain
118119 }
119120 } )
@@ -160,7 +161,7 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
160161
161162 // 生成连接配置
162163 const generateConnectionConfig = (
163- domains : Array < { domain : string ; protocol : string } > | null | undefined ,
164+ domains : Array < { domain : string ; port ?: number ; protocol : string } > | null | undefined ,
164165 path : string | null | undefined ,
165166 serverName : string ,
166167 localConfig ?: unknown ,
@@ -179,22 +180,7 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
179180 // HTTP/SSE 模式
180181 if ( domains && domains . length > 0 && path && domainIndex < domains . length ) {
181182 const domain = domains [ domainIndex ]
182- // 处理域名和端口,隐藏默认端口(80/443)
183- const formatDomainWithPort = ( domainStr : string , protocol : string ) => {
184- const [ host , port ] = domainStr . split ( ':' ) ;
185- // 如果没有端口,直接返回域名
186- if ( ! port ) return domainStr ;
187-
188- // 隐藏 HTTP 默认端口 80
189- if ( protocol === 'http' && port === '80' ) return host ;
190- // 隐藏 HTTPS 默认端口 443
191- if ( protocol === 'https' && port === '443' ) return host ;
192-
193- // 其他情况保留端口
194- return domainStr ;
195- } ;
196-
197- const formattedDomain = formatDomainWithPort ( domain . domain , domain . protocol ) ;
183+ const formattedDomain = formatDomainWithPort ( domain . domain , domain . port , domain . protocol ) ;
198184 const baseUrl = `${ domain . protocol } ://${ formattedDomain } ` ;
199185 let fullUrl = `${ baseUrl } ${ path || '/' } ` ;
200186
@@ -988,12 +974,12 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
988974
989975 // 获取所有唯一域名的简化版本
990976 const getAllUniqueDomains = ( ) => {
991- const domainsMap = new Map < string , { domain : string ; protocol : string } > ( )
977+ const domainsMap = new Map < string , { domain : string ; port ?: number ; protocol : string } > ( )
992978
993979 routes . forEach ( route => {
994980 if ( route . domains && route . domains . length > 0 ) {
995981 route . domains . forEach ( ( domain : any ) => {
996- const key = `${ domain . protocol } ://${ domain . domain } `
982+ const key = `${ domain . protocol } ://${ domain . domain } ${ domain . port ? `: ${ domain . port } ` : '' } `
997983 domainsMap . set ( key , domain )
998984 } )
999985 }
@@ -1005,10 +991,13 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
1005991 const allUniqueDomains = getAllUniqueDomains ( )
1006992
1007993 // 生成域名选择器选项
1008- const agentDomainOptions = allUniqueDomains . map ( ( domain , index ) => ( {
1009- value : index ,
1010- label : `${ domain . protocol . toLowerCase ( ) } ://${ domain . domain } `
1011- } ) )
994+ const agentDomainOptions = allUniqueDomains . map ( ( domain , index ) => {
995+ const formattedDomain = formatDomainWithPort ( domain . domain , domain . port , domain . protocol ) ;
996+ return {
997+ value : index ,
998+ label : `${ domain . protocol . toLowerCase ( ) } ://${ formattedDomain } `
999+ }
1000+ } )
10121001
10131002 // 生成路由显示文本(优化方法显示)
10141003 const getRouteDisplayText = ( route : any , domainIndex : number = 0 ) => {
@@ -1021,11 +1010,13 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
10211010 let domainInfo = ''
10221011 if ( allUniqueDomains . length > 0 && allUniqueDomains . length > domainIndex ) {
10231012 const selectedDomain = allUniqueDomains [ domainIndex ]
1024- domainInfo = `${ selectedDomain . protocol . toLowerCase ( ) } ://${ selectedDomain . domain } `
1013+ const formattedDomain = formatDomainWithPort ( selectedDomain . domain , selectedDomain . port , selectedDomain . protocol ) ;
1014+ domainInfo = `${ selectedDomain . protocol . toLowerCase ( ) } ://${ formattedDomain } `
10251015 } else if ( route . domains && route . domains . length > 0 ) {
10261016 // 回退到路由的第一个域名
10271017 const domain = route . domains [ 0 ]
1028- domainInfo = `${ domain . protocol . toLowerCase ( ) } ://${ domain . domain } `
1018+ const formattedDomain = formatDomainWithPort ( domain . domain , domain . port , domain . protocol ) ;
1019+ domainInfo = `${ domain . protocol . toLowerCase ( ) } ://${ formattedDomain } `
10291020 }
10301021
10311022 // 构建基本路由信息(匹配符号直接加到path后面)
@@ -1051,12 +1042,14 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
10511042 const getFullUrl = ( route : any , domainIndex : number = 0 ) => {
10521043 if ( allUniqueDomains . length > 0 && allUniqueDomains . length > domainIndex ) {
10531044 const selectedDomain = allUniqueDomains [ domainIndex ]
1045+ const formattedDomain = formatDomainWithPort ( selectedDomain . domain , selectedDomain . port , selectedDomain . protocol ) ;
10541046 const path = route . match ?. path ?. value || '/'
1055- return `${ selectedDomain . protocol . toLowerCase ( ) } ://${ selectedDomain . domain } ${ path } `
1047+ return `${ selectedDomain . protocol . toLowerCase ( ) } ://${ formattedDomain } ${ path } `
10561048 } else if ( route . domains && route . domains . length > 0 ) {
10571049 const domain = route . domains [ 0 ]
1050+ const formattedDomain = formatDomainWithPort ( domain . domain , domain . port , domain . protocol ) ;
10581051 const path = route . match ?. path ?. value || '/'
1059- return `${ domain . protocol . toLowerCase ( ) } ://${ domain . domain } ${ path } `
1052+ return `${ domain . protocol . toLowerCase ( ) } ://${ formattedDomain } ${ path } `
10601053 }
10611054 return ''
10621055 }
@@ -1270,11 +1263,14 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
12701263 { /* 域名信息 */ }
12711264 < div >
12721265 < div className = "text-xs text-gray-500 mb-1" > 域名:</ div >
1273- { route . domains ?. map ( ( domain : any , domainIndex : number ) => (
1274- < div key = { domainIndex } className = "text-sm" >
1275- < span className = "font-mono" > { domain . protocol . toLowerCase ( ) } ://{ domain . domain } </ span >
1276- </ div >
1277- ) ) }
1266+ { route . domains ?. map ( ( domain : any , domainIndex : number ) => {
1267+ const formattedDomain = formatDomainWithPort ( domain . domain , domain . port , domain . protocol ) ;
1268+ return (
1269+ < div key = { domainIndex } className = "text-sm" >
1270+ < span className = "font-mono" > { domain . protocol . toLowerCase ( ) } ://{ formattedDomain } </ span >
1271+ </ div >
1272+ )
1273+ } ) }
12781274 </ div >
12791275
12801276 { /* 匹配规则 */ }
@@ -1346,12 +1342,12 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
13461342
13471343 // 获取所有唯一域名的简化版本
13481344 const getAllModelUniqueDomains = ( ) => {
1349- const domainsMap = new Map < string , { domain : string ; protocol : string } > ( )
1345+ const domainsMap = new Map < string , { domain : string ; port ?: number ; protocol : string } > ( )
13501346
13511347 routes . forEach ( route => {
13521348 if ( route . domains && route . domains . length > 0 ) {
13531349 route . domains . forEach ( ( domain : any ) => {
1354- const key = `${ domain . protocol } ://${ domain . domain } `
1350+ const key = `${ domain . protocol } ://${ domain . domain } ${ domain . port ? `: ${ domain . port } ` : '' } `
13551351 domainsMap . set ( key , domain )
13561352 } )
13571353 }
@@ -1363,10 +1359,13 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
13631359 const allModelUniqueDomains = getAllModelUniqueDomains ( )
13641360
13651361 // 生成域名选择器选项
1366- const modelDomainOptions = allModelUniqueDomains . map ( ( domain , index ) => ( {
1367- value : index ,
1368- label : `${ domain . protocol . toLowerCase ( ) } ://${ domain . domain } `
1369- } ) )
1362+ const modelDomainOptions = allModelUniqueDomains . map ( ( domain , index ) => {
1363+ const formattedDomain = formatDomainWithPort ( domain . domain , domain . port , domain . protocol ) ;
1364+ return {
1365+ value : index ,
1366+ label : `${ domain . protocol . toLowerCase ( ) } ://${ formattedDomain } `
1367+ }
1368+ } )
13701369
13711370 // 生成匹配类型前缀文字
13721371 const getMatchTypePrefix = ( matchType : string ) => {
@@ -1393,11 +1392,13 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
13931392 let domainInfo = ''
13941393 if ( allModelUniqueDomains . length > 0 && allModelUniqueDomains . length > domainIndex ) {
13951394 const selectedDomain = allModelUniqueDomains [ domainIndex ]
1396- domainInfo = `${ selectedDomain . protocol . toLowerCase ( ) } ://${ selectedDomain . domain } `
1395+ const formattedDomain = formatDomainWithPort ( selectedDomain . domain , selectedDomain . port , selectedDomain . protocol ) ;
1396+ domainInfo = `${ selectedDomain . protocol . toLowerCase ( ) } ://${ formattedDomain } `
13971397 } else if ( route . domains && route . domains . length > 0 ) {
13981398 // 回退到路由的第一个域名
13991399 const domain = route . domains [ 0 ]
1400- domainInfo = `${ domain . protocol . toLowerCase ( ) } ://${ domain . domain } `
1400+ const formattedDomain = formatDomainWithPort ( domain . domain , domain . port , domain . protocol ) ;
1401+ domainInfo = `${ domain . protocol . toLowerCase ( ) } ://${ formattedDomain } `
14011402 }
14021403
14031404 // 构建基本路由信息(匹配符号直接加到path后面)
@@ -1431,12 +1432,14 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
14311432 const getFullUrl = ( route : any , domainIndex : number = 0 ) => {
14321433 if ( allModelUniqueDomains . length > 0 && allModelUniqueDomains . length > domainIndex ) {
14331434 const selectedDomain = allModelUniqueDomains [ domainIndex ]
1435+ const formattedDomain = formatDomainWithPort ( selectedDomain . domain , selectedDomain . port , selectedDomain . protocol ) ;
14341436 const path = route . match ?. path ?. value || '/'
1435- return `${ selectedDomain . protocol . toLowerCase ( ) } ://${ selectedDomain . domain } ${ path } `
1437+ return `${ selectedDomain . protocol . toLowerCase ( ) } ://${ formattedDomain } ${ path } `
14361438 } else if ( route . domains && route . domains . length > 0 ) {
14371439 const domain = route . domains [ 0 ]
1440+ const formattedDomain = formatDomainWithPort ( domain . domain , domain . port , domain . protocol ) ;
14381441 const path = route . match ?. path ?. value || '/'
1439- return `${ domain . protocol . toLowerCase ( ) } ://${ domain . domain } ${ path } `
1442+ return `${ domain . protocol . toLowerCase ( ) } ://${ formattedDomain } ${ path } `
14401443 }
14411444 return null
14421445 }
@@ -1564,11 +1567,14 @@ export function ApiProductLinkApi({ apiProduct, linkedService, onLinkedServiceUp
15641567 { /* 域名信息 */ }
15651568 < div >
15661569 < div className = "text-xs text-gray-500 mb-1" > 域名:</ div >
1567- { route . domains ?. map ( ( domain : any , domainIndex : number ) => (
1568- < div key = { domainIndex } className = "text-sm" >
1569- < span className = "font-mono" > { domain . protocol . toLowerCase ( ) } ://{ domain . domain } </ span >
1570- </ div >
1571- ) ) }
1570+ { route . domains ?. map ( ( domain : any , domainIndex : number ) => {
1571+ const formattedDomain = formatDomainWithPort ( domain . domain , domain . port , domain . protocol ) ;
1572+ return (
1573+ < div key = { domainIndex } className = "text-sm" >
1574+ < span className = "font-mono" > { domain . protocol . toLowerCase ( ) } ://{ formattedDomain } </ span >
1575+ </ div >
1576+ )
1577+ } ) }
15721578 </ div >
15731579
15741580 { /* 匹配规则 */ }
0 commit comments