Skip to content

Commit ad22663

Browse files
refactor: share http://localhost string
1 parent 997afbb commit ad22663

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/path.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export type QueryValue =
99
| undefined;
1010
export type QueryObject = Record<string, QueryValue | QueryValue[]>;
1111

12+
const DEFAULT_BASE_URL = "http://localhost";
13+
1214
/**
1315
* Removes the leading slash from the given path if it has one.
1416
*/
@@ -80,7 +82,7 @@ export function withQuery(input: string, query: QueryObject): string {
8082
let searchParams: URLSearchParams;
8183

8284
if (input.includes("?")) {
83-
url = new URL(input, "http://localhost");
85+
url = new URL(input, DEFAULT_BASE_URL);
8486
searchParams = new URLSearchParams(url.search);
8587
} else {
8688
searchParams = new URLSearchParams();
@@ -109,7 +111,7 @@ export function withQuery(input: string, query: QueryObject): string {
109111
if (url) {
110112
url.search = queryString;
111113
let urlWithQuery = url.toString();
112-
if (urlWithQuery.startsWith("http://localhost")) {
114+
if (urlWithQuery.startsWith(DEFAULT_BASE_URL)) {
113115
urlWithQuery = urlWithQuery.slice(16);
114116
}
115117
return urlWithQuery;

0 commit comments

Comments
 (0)