-
Notifications
You must be signed in to change notification settings - Fork 234
Closed
Description
Bug Report
I tried to put a https proxy (for example fiddler) for graph client in node environment.
But I found the request seems not sent to the proxy, as I cannot observe the request in fiddler.
I tried to import "isomorphic-fetch"; as the guide shows, but it still failed.
If I customize the graph client by specifying the http message handler to use fetch from "isomorphic-fetch".
It works as I could observe the request in fiddler.
Here is the code. Using node 18
import { Client, Context, Middleware } from "@microsoft/microsoft-graph-client";
import { HttpsProxyAgent } from "hpagent";
import fetch from "isomorphic-fetch";
class HTTPMessageHandler implements Middleware {
/**
* @public
* @async
* To execute the current middleware
* @param {Context} context - The request context object
* @returns A promise that resolves to nothing
*/
public async execute(context: Context): Promise<void> {
context.response = await fetch(context.request, context.options);
}
}
async function main() {
try {
const agent = new HttpsProxyAgent({
proxy: 'http://127.0.0.1:8888', // Fiddler proxy address
rejectUnauthorized: false,
})
const graphClient = Client.initWithMiddleware({middleware: new HTTPMessageHandler()});
const api = graphClient.api("/me")
const result = await api.option("agent", agent).get();
console.log(result);
} catch (error: any) {
console.log(error.message);
}
}
main();
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels