(appPortOrUrl: string | number, url: string, hostname?: string)
| 69 | } |
| 70 | |
| 71 | export function getFullUrl(appPortOrUrl: string | number, url: string, hostname?: string) { |
| 72 | let fullUrl = |
| 73 | typeof appPortOrUrl === "string" && appPortOrUrl.startsWith("http") |
| 74 | ? appPortOrUrl |
| 75 | : `http://${hostname ? hostname : "localhost"}:${appPortOrUrl}${url}` |
| 76 | |
| 77 | if (typeof appPortOrUrl === "string" && url) { |
| 78 | const parsedUrl = new URL(fullUrl) |
| 79 | const parsedPathQuery = new URL(url, fullUrl) |
| 80 | |
| 81 | parsedUrl.search = parsedPathQuery.search |
| 82 | parsedUrl.pathname = parsedPathQuery.pathname |
| 83 | |
| 84 | if (hostname && parsedUrl.hostname === "localhost") { |
| 85 | parsedUrl.hostname = hostname |
| 86 | } |
| 87 | fullUrl = parsedUrl.toString() |
| 88 | } |
| 89 | return fullUrl |
| 90 | } |
| 91 | |
| 92 | export function renderViaAPI(app, pathname, query) { |
| 93 | const url = `${pathname}${query ? `?${qs.stringify(query)}` : ""}` |
no test coverage detected