gRPC Support (#20)

This commit is contained in:
Gregory Schier
2024-02-09 05:01:00 -08:00
committed by GitHub
parent 219a6b78da
commit 394beb374e
162 changed files with 6670 additions and 1770 deletions

View File

@@ -1,6 +1,6 @@
import type { HttpRequest } from './models';
import type { GrpcRequest, HttpRequest } from './models';
export function fallbackRequestName(r: HttpRequest | null): string {
export function fallbackRequestName(r: HttpRequest | GrpcRequest | null): string {
if (r == null) return '';
if (r.name) {
@@ -9,17 +9,22 @@ export function fallbackRequestName(r: HttpRequest | null): string {
const withoutVariables = r.url.replace(/\$\{\[[^\]]+]}/g, '');
if (withoutVariables.trim() === '') {
return 'New Request';
return r.model === 'http_request' ? 'New HTTP Request' : 'new gRPC Request';
}
const fixedUrl = r.url.match(/^https?:\/\//) ? r.url : 'http://' + r.url;
try {
const url = new URL(fixedUrl);
const pathname = url.pathname === '/' ? '' : url.pathname;
return `${url.host}${pathname}`;
} catch (_) {
// Nothing
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;