Skip to content

Unable to use the library through a proxy #97

Closed

Description

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.

Activity

  1. muthurathinam commented on Aug 22, 2018

    @muthurathinam
    Contributor

    Jérome Morino (@jmorino) Good one. Will implement a way to pass in the options for fetch.

    862171

  2. jmorino commented on Aug 22, 2018

    @jmorino
    Author

    thanks Muthurathinam (@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;
    
  3. muthurathinam commented on Sep 22, 2018

    @muthurathinam
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions