From 5e05fe08e604faabc79e98fc183036aa61bbbbc4 Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 14 Oct 2023 23:06:51 +0800 Subject: [PATCH] alter getBaseUrl --- src/url-helper.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/url-helper.ts b/src/url-helper.ts index d12a82a..3ef4ed9 100644 --- a/src/url-helper.ts +++ b/src/url-helper.ts @@ -1,6 +1,6 @@ import * as assert from 'assert' -import {URL} from 'url' -import {IGitSourceSettings} from './git-source-settings' +import { URL } from 'url' +import { IGitSourceSettings } from './git-source-settings' export function getFetchUrl(settings: IGitSourceSettings): string { assert.ok( @@ -16,7 +16,7 @@ export function getFetchUrl(settings: IGitSourceSettings): string { } // "origin" is SCHEME://HOSTNAME[:PORT] - const baseURL = getBaseUrl(serviceUrl.href) + const baseURL = getBaseUrl(serviceUrl) return `${baseURL}/${encodedOwner}/${encodedName}` } @@ -28,9 +28,8 @@ export function getServerUrl(url?: string): URL { return new URL(urlValue) } -export function getBaseUrl(url: string): string { - const matcher = url.match(/^[^?]+/) - return (matcher && matcher[0].replace(/\/+$/g, '')) || '' +function getBaseUrl(u: URL) { + return u.protocol + "//" + u.host + u.pathname.replace(/\/+$/g, ''); } export function getServerApiUrl(url?: string): string {