GithubHelp home page GithubHelp logo

Comments (5)

yonilerner avatar yonilerner commented on August 21, 2024 7

FWIW, I just created an https-proxy-agent.d.ts file in my project with:

declare module 'https-proxy-agent' {
    import * as https from 'https'

    namespace HttpsProxyAgent {
        interface HttpsProxyAgentOptions {
            host: string
            port: number
            secureProxy?: boolean
            headers?: {
                [key: string]: string
            }
            [key: string]: any
        }
    }
    
    // HttpsProxyAgent doesnt *actually* extend https.Agent, but for my purposes I want it to pretend that it does
    class HttpsProxyAgent extends https.Agent {
        constructor(opts: HttpsProxyAgent.HttpsProxyAgentOptions)
    }

    export = HttpsProxyAgent
}

And I use

import * as HttpsProxyAgent from 'https-proxy-agent'
import {HttpsProxyAgentOptions} from 'https-proxy-agent'

// HttpsProxyAgent.HttpsProxyAgentOptions would also work
const opts: HttpsProxyAgentOptions = {...}

const agent = new HttpsProxyAgent(opts)

from proxy-agents.

nickelswitte avatar nickelswitte commented on August 21, 2024 5

I am not sure if this is the right place to talk about this, but using the workaround provided by @MichaelHindley, I get an error when passing the https-proxy-agent to node-fetch.

When trying to do

fetch(url, { 
        method: 'POST', 
        headers: headers, 
        agent: agent, 
        body: data
})

I will get an error, that the agent is not of the correct type. The full error is below.

(property) RequestInit.agent?: Agent | ((parsedUrl: URL) => Agent)

Type 'HttpsProxyAgent' is not assignable to type 'Agent | ((parsedUrl: URL) => Agent)'.
Property 'freeSockets' is missing in type 'HttpsProxyAgent' but required in type 'Agent'.ts(2322)

http.d.ts(361, 18): 'freeSockets' is declared here.
index.d.ts(55, 5): The expected type comes from property 'agent' which is declared here on type 'RequestInit'

This can be fixed using agent: agent as any, but does not seem like a good solution.

How to properly deal with this issue?

from proxy-agents.

TooTallNate avatar TooTallNate commented on August 21, 2024 2

Fixed by #66.

from proxy-agents.

MichaelHindley avatar MichaelHindley commented on August 21, 2024 2

@TooTallNate
Just a heads up, using the index.d.ts from master to work with the currently published 2.2.1 package doesn't work with the signature defined in the constructor, which no longer accepts proxy as a string.

Might just be a intermediate change for upcoming bc breaks, but figured it might be good to share this finding just in case :)

// index.d.ts - master
class HttpsProxyAgent extends https.Agent {
    constructor(opts: HttpsProxyAgent.HttpsProxyAgentOptions)
  }

 const agent = new HttpsProxyAgent({
   host,
   port,
 }); // fails silently when supplied to ws
// index.d.ts - modified
class HttpsProxyAgent extends https.Agent {
  constructor(proxy: string)
}

const agent = new HttpsProxyAgent(proxyString); // works

from proxy-agents.

yesworld avatar yesworld commented on August 21, 2024 1

@yonilerner Thank you man!

from proxy-agents.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.