diff --git a/src-web/lib/fallbackRequestName.ts b/src-web/lib/fallbackRequestName.ts index 27ad3c70..9c7525e6 100644 --- a/src-web/lib/fallbackRequestName.ts +++ b/src-web/lib/fallbackRequestName.ts @@ -3,31 +3,25 @@ import type { GrpcRequest, HttpRequest } from './models'; export function fallbackRequestName(r: HttpRequest | GrpcRequest | null): string { if (r == null) return ''; + // Return name if it has one if (r.name) { return r.name; } - const withoutVariables = r.url.replace(/\$\{\[\s*([^\]]+)\s*]}/g, '$1'); + // Replace variable syntax with variable name + const withoutVariables = r.url.replace(/\$\{\[\s*([^\]\s]+)\s*]}/g, '$1'); if (withoutVariables.trim() === '') { return r.model === 'http_request' ? 'New HTTP Request' : 'new gRPC Request'; } - const fixedUrl = withoutVariables.match(/^https?:\/\//) - ? withoutVariables - : 'http://' + withoutVariables; - + // GRPC gets nice short names if (r.model === 'grpc_request' && r.service != null && r.method != null) { const shortService = r.service.split('.').pop(); return `${shortService}/${r.method}`; - } else { - try { - const url = new URL(fixedUrl); - const pathname = url.pathname === '/' ? '' : url.pathname; - return `${url.host}${pathname}`; - } catch (_) { - // Nothing - } } - return r.url; + // Strip unnecessary protocol + const withoutProto = withoutVariables.replace(/^https?:\/\//, ''); + + return withoutProto; }