export function extractUrlParts()

in util/upload/src/lib/utils.ts [74:94]


export function extractUrlParts(urlString: string): UrlParts | null {
    try {
        // Use the URL constructor to parse the URL
        const url = new URL(urlString);

        // Extract the protocol, hostname (host), and port
        const protocol = url.protocol; // includes the ':' at the end
        const host = url.hostname;     // host without port
        const port = url.port || (protocol === 'https:' ? '443' : '80'); // default ports
        const protocolWithoutColon = protocol.replace(':', ''); // if you want protocol without ':'

        return {
            protocol: protocolWithoutColon,
            host: host,
            port: Number(port)
        };
    } catch (error) {
        logError(`Invalid URL: ${error}`);
        return null;
    }
}