How to use the proxy-chain.parseUrl function in proxy-chain

To help you get started, we’ve selected a few proxy-chain examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apifytech / apify-js / src / puppeteer.js View on Github external
const launchPuppeteerWithProxy = async (puppeteer, opts) => {
    // Parse and validate proxy URL
    const parsedProxyUrl = parseUrl(opts.proxyUrl);
    if (!parsedProxyUrl.host || !parsedProxyUrl.port) {
        throw new Error('Invalid "proxyUrl" option: both hostname and port must be provided.');
    }
    if (!/^(http|https|socks4|socks5)$/.test(parsedProxyUrl.scheme)) {
        throw new Error(`Invalid "proxyUrl" option: Unsupported scheme (${parsedProxyUrl.scheme}).`);
    }

    // Anonymize proxy URL if it has username or password
    let anonymizedProxyUrl = null;
    if (parsedProxyUrl.username || parsedProxyUrl.password) {
        if (parsedProxyUrl.scheme !== 'http') {
            throw new Error('Invalid "proxyUrl" option: authentication is only supported for HTTP proxy type.');
        }
        anonymizedProxyUrl = await anonymizeProxy(opts.proxyUrl);
    }

proxy-chain

Node.js implementation of a proxy server (think Squid) with support for SSL, authentication, upstream proxy chaining, and protocol tunneling.

Apache-2.0
Latest version published 7 months ago

Package Health Score

74 / 100
Full package analysis