Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use the library through a proxy #97

Closed
jmorino opened this issue Aug 16, 2018 · 3 comments
Closed

Unable to use the library through a proxy #97

jmorino opened this issue Aug 16, 2018 · 3 comments
Labels

Comments

@jmorino
Copy link

jmorino commented Aug 16, 2018

I need to call Graph API through a corporate proxy, but I found no mean to pass options to the underlying fetch() library, in order to specify the proxy URL or a custom HTTP(S) agent.

I think it would be great to provide a way to pass options to fetch(), so it will solve any issue about proxy, timeout or any environment-specific needs.

@muthurathinam
Copy link
Contributor

muthurathinam commented Aug 22, 2018

@jmorino Good one. Will implement a way to pass in the options for fetch.

862171

@jmorino
Copy link
Author

jmorino commented Aug 22, 2018

thanks @muthurathinam !

In the meantime, here is my workaround if it can help someone: I just extend the globally-exposed Request class and set a custom HTTPS agent.

'use strict';

import { Client } from '@microsoft/microsoft-graph-client'
import HttpsProxyAgent from 'https-proxy-agent'

const OriginalRequest = global.Request;
global.Request = class extends OriginalRequest {
	constructor(...args) {
		super(...args);
		
		const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || null;
		const noproxy = process.env.NO_PROXY || process.env.no_proxy || '';
		const needProxy = proxy && noproxy.split(',').every(h => this.url.indexOf(h.trim()) === -1);
		if (needProxy) {
			this.agent = new HttpsProxyAgent(proxy)
		}
	}
}

export default Client;

@muthurathinam
Copy link
Contributor

Fixed in this PR and released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants