@@ -15,6 +15,7 @@ import {
1515 RetryHandlerOptions ,
1616 TelemetryHandler
1717} from '@microsoft/microsoft-graph-client' ;
18+ import { SessionCache , storageAvailable } from '../utils/SessionCache' ;
1819import { MgtBaseComponent } from '../components/baseComponent' ;
1920import { Graph } from '../Graph' ;
2021import { chainMiddleware } from '../utils/GraphHelpers' ;
@@ -74,13 +75,21 @@ class MockMiddleware implements Middleware {
7475 */
7576 private _nextMiddleware : Middleware ;
7677
77- private static _baseUrl ;
78+ private _baseUrl : string ;
79+
80+ private _session : SessionCache ;
81+
82+ constructor ( ) {
83+ if ( storageAvailable ( 'sessionStorage' ) ) {
84+ this . _session = new SessionCache ( ) ;
85+ }
86+ }
7887
7988 // tslint:disable-next-line: completed-docs
8089 public async execute ( context : Context ) : Promise < void > {
8190 try {
82- const baseUrl = await MockMiddleware . getBaseUrl ( ) ;
83- context . request = baseUrl + escape ( context . request as string ) ;
91+ const baseUrl = await this . getBaseUrl ( ) ;
92+ context . request = baseUrl + encodeURIComponent ( context . request as string ) ;
8493 } catch ( error ) {
8594 // ignore error
8695 }
@@ -96,15 +105,21 @@ class MockMiddleware implements Middleware {
96105 this . _nextMiddleware = next ;
97106 }
98107
99- private static async getBaseUrl ( ) {
108+ private async getBaseUrl ( ) {
100109 if ( ! this . _baseUrl ) {
101- try {
102- // get the url we should be using from the endpoint service
103- let response = await fetch ( 'https://cdn.graph.office.net/en-us/graph/api/proxy/endpoint' ) ;
104- this . _baseUrl = ( await response . json ( ) ) + '?url=' ;
105- } catch {
106- // fallback to hardcoded value
107- this . _baseUrl = 'https://proxy.apisandbox.msdn.microsoft.com/svc?url=' ;
110+ const sessionEndpoint = this . _session ?. getItem ( 'endpointURL' ) ;
111+ if ( sessionEndpoint ) {
112+ this . _baseUrl = sessionEndpoint ;
113+ } else {
114+ try {
115+ // get the url we should be using from the endpoint service
116+ let response = await fetch ( 'https://cdn.graph.office.net/en-us/graph/api/proxy/endpoint' ) ;
117+ this . _baseUrl = ( await response . json ( ) ) + '?url=' ;
118+ } catch {
119+ // fallback to hardcoded value
120+ this . _baseUrl = 'https://proxy.apisandbox.msdn.microsoft.com/svc?url=' ;
121+ }
122+ this . _session ?. setItem ( 'endpointURL' , this . _baseUrl ) ;
108123 }
109124 }
110125
0 commit comments