question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Working behind proxy

See original GitHub issue

Is your feature request related to a problem? Please describe.

We need our continuous integration to upload the openapi yaml to the Redocly API registry, but we always get time out, we think the reason for this timeout is that we are behind an enterprise proxy.

FetchError: request to https://api.redoc.ly/registry failed, reason: connect ETIMEDOUT 34.238.30.35:44 at ClientRequest.<anonymous> (C:\ (...) \AppData\Roaming\npm\node_modules\@redocly\openapi-cli\node_modules\node-fetch\lib\index.js:1491:11) at ClientRequest.emit (node:events:390:28) at TLSSocket.socketErrorListener (node:_http_client:447:9) at TLSSocket.emit (node:events:390:28) at emitErrorNT (node:internal/streams/destroy:157:8) at emitErrorCloseNT (node:internal/streams/destroy:122:3) at processTicksAndRejections (node:internal/process/task_queues:83:21) { type: 'system', errno: 'ETIMEDOUT', code: 'ETIMEDOUT' }

Authorization failed. Please check if you entered a valid API key.

Describe the solution you’d like

We would like openapi cli working behind a proxy server.

Describe alternatives you’ve considered

We did a quick modification to your code in registry-api.ts to handle the proxy connection:

const HttpsProxyAgent = require('https-proxy-agent');
private async request(path = '', options: RequestInit = {}, region?: Region) {
    const headers = Object.assign({}, options.headers || {}, { 'x-redocly-cli-version': version });
    if (!headers.hasOwnProperty('authorization')) { throw new Error('Unauthorized'); }
const proxyAgent = new HttpsProxyAgent('XXX:XXX/');
    const response = await fetch(`${this.getBaseUrl(region)}${path}`,  Object.assign({}, options, { headers }, { agent: proxyAgent}) );
    if (response.status === 401) { throw new Error('Unauthorized'); }
    if (response.status === 404) {
      const body: RegistryApiTypes.NotFoundProblemResponse = await response.json();
      throw new Error(body.code);
    }
    return response;
  }

(see: https://www.scrapingbee.com/blog/proxy-node-fetch/)

This seems to work for the login command but still timesout for the push command:

FetchError: request to (...) host failed, reason: connect ETIMEDOUT 52.216.108.107:443 at ClientRequest.<anonymous> ( (...) \openapi-cli\node_modules\node-fetch\lib\index.js:1491:11) at ClientRequest.emit (node:events:390:28) at ClientRequest.emit (node:domain:475:12) at TLSSocket.socketErrorListener (node:_http_client:447:9) at TLSSocket.emit (node:events:390:28) at TLSSocket.emit (node:domain:475:12) at emitErrorNT (node:internal/streams/destroy:157:8) at emitErrorCloseNT (node:internal/streams/destroy:122:3) at processTicksAndRejections (node:internal/process/task_queues:83:21) { type: 'system', errno: 'ETIMEDOUT', code: 'ETIMEDOUT' }

Additional context

I don’t know if it matters but we do have an enterprise license for Redocly.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
joaonlopescommented, Jan 25, 2022

Hello,

just an update on this. I managed to successfully push the files after modifying your code in push.ts.

const HttpsProxyAgent = require('https-proxy-agent');
function uploadFileToS3(url: string, filePathOrBuffer: string | Buffer) {
  const fileSizeInBytes =
    typeof filePathOrBuffer === 'string'
      ? fs.statSync(filePathOrBuffer).size
      : filePathOrBuffer.byteLength;
  let readStream =
    typeof filePathOrBuffer === 'string' ? fs.createReadStream(filePathOrBuffer) : filePathOrBuffer;

	const proxyAgent = new HttpsProxyAgent('XXX:XXX/');

  return fetch(url, {
	agent: proxyAgent,
    method: 'PUT',
    headers: {
      'Content-Length': fileSizeInBytes.toString(),
    },
    body: readStream,
  });
}

Hope this helps.

Thank you

1reaction
joaonlopescommented, Feb 17, 2022

We just use the REDOCLY_PROXY environment variable and it works fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a Proxy Server and How Does it Work?
A proxy server acts as a gateway between you and the internet. It's an intermediary server separating end users from the websites they...
Read more >
How to Know If You're Behind a Proxy Server
Click the “Connections” tab in the Internet Options window. Click the “LAN Settings” button. If there is a check mark in the box...
Read more >
Working behind a proxy - Documentation
Setting the proxy for Git. Open a command prompt; Run the following commands replacing USERNAME , PASSWORD , PROXY_ADDRESS , and PROXY_PORT with ......
Read more >
Work behind a proxy
Supply the proxy username and password using the outgoingproxyuser and outgoingproxypass parameters in the command line, as shown in the following code snippet....
Read more >
What is a Proxy Server? How does it work?
A proxy server is a system or router that provides a gateway between users and the internet. Therefore, it helps prevent cyber attackers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found