(url?: string)
| 13 | |
| 14 | /** Returns an `URL` like object to make requests/redirects from server-side */ |
| 15 | export default function parseUrl(url?: string): InternalUrl { |
| 16 | const defaultUrl = new URL("http://localhost:3000/api/auth") |
| 17 | |
| 18 | if (url && !url.startsWith("http")) { |
| 19 | url = `https://${url}` |
| 20 | } |
| 21 | |
| 22 | const _url = new URL(url ?? defaultUrl) |
| 23 | const path = (_url.pathname === "/" ? defaultUrl.pathname : _url.pathname) |
| 24 | // Remove trailing slash |
| 25 | .replace(/\/$/, "") |
| 26 | |
| 27 | const base = `${_url.origin}${path}` |
| 28 | |
| 29 | return { |
| 30 | origin: _url.origin, |
| 31 | host: _url.host, |
| 32 | path, |
| 33 | base, |
| 34 | toString: () => base, |
| 35 | } |
| 36 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…