(resolved: string | null)
| 17 | } |
| 18 | |
| 19 | function toRelativePath(resolved: string | null): string | null { |
| 20 | if (!resolved) return null; |
| 21 | |
| 22 | // Only attempt conversion for absolute URLs |
| 23 | if (/^https?:\/\//.test(resolved) === false) return resolved; |
| 24 | |
| 25 | try { |
| 26 | const resolvedUrl = new URL(resolved); |
| 27 | const publicBase = new URL(getPublicURL()); |
| 28 | |
| 29 | if (resolvedUrl.protocol === publicBase.protocol && resolvedUrl.host === publicBase.host) { |
| 30 | return extractPath(resolvedUrl.toString()); |
| 31 | } |
| 32 | } catch { |
| 33 | // Not a valid URL, return as-is |
| 34 | } |
| 35 | |
| 36 | return resolved; |
| 37 | } |
| 38 | |
| 39 | return { redirect, resolveRedirect }; |
| 40 | } |
no test coverage detected