export interface InternalUrl { default origin : string ; default host : string ; default path : string ; default base : string ; default toString : ( ) => string ; } export default function parseUrl ( url ? ) { const defaultUrl = new URL ( "http://localhost:3000/api/auth" ) ; if ( url && ! url . startsWith ( "http" ) ) { url = `https://${ url }` ; } const _url = new URL ( url ?? defaultUrl ) ; const path = ( _url . pathname === "/" ? defaultUrl . pathname : _url . pathname ) . replace ( /\/$/ , "" ) ; const base = `${ _url . origin }${ path }` ; return { origin : _url . origin , host : _url . host , path , base , toString : ( ) => base , } ; }