hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client

Home Page:https://heyapi.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting a custom httpsAgent on the generated AxiosInstance

kimzeevaarders opened this issue · comments

Description

Hi,
I like the project very much and its working fine, however i'm now running into a small problem:

I'm using axios for my generated http client, but I can't seem to find a way to set a custom httpsAgent:

Example:

const result = await axios.post(
    `https://${url}/login`,
    body,
    {
      httpsAgent: new https.Agent({
        rejectUnauthorized: false
      })
    }
  )

I need this to import our rootca certificate since it's self-signed...

Is this even possible?

@kimzeevaarders this will be better supported with client packages. @mrlubos can provide more info

Hi @jordanshatford thx for the quick feedback. Does this mean it's currently not possible, but will be in the future? Just asking since I need to go live relatively soon haha :)

@kimzeevaarders it is currently not possible.

ah that's too bad thx for responding though 👍

In case this gets implemented please let me know though, perhaps I can still switch over then 👍

hmmmm @jordanshatford @mrlubos I managed to set a httpsAgent on the axiosRequestConfig over a request interceptor. It seems to do the trick:

const requestInterceptor = OpenAPI.interceptors.request;

requestInterceptor.use((request) => {
    request.httpsAgent = new Agent({
        ca: process.env.TRUSTED_CAS
    });

    return request;
});

Can you guys verify this is a good workaround or are there some caveats using this approach?

@kimzeevaarders ahh yes. You can use interceptors. You can also set axios interceptors on the global axios instance too if you prefer that

Hi @jordanshatford cool, thx for confirming. No i'd rather only set it when needed, so this is perfect for me!

Workaround successfull over interceptor

commented

@kimzeevaarders if you're able to upgrade, the new Axios client is available now https://www.npmjs.com/package/@hey-api/client-axios

Docs: https://heyapi.vercel.app/openapi-ts/clients.html#axios

Would love your thoughts if you give it a try!