@@ -135,33 +135,33 @@ In order to create a fetchable build config that contains all required keys for
135135
136136```
137137
138- Take the following example using ` axios ` :
138+ Take the following example using ` fetch ` :
139139
140140` unity-api.ts `
141141
142142``` ts
143- import axios , { AxiosResponse } from ' axios' ;
144143import { UnityLoaderConfig } from ' react-unity-renderer' ;
145144
146- function fetchLoaderConfig(baseUrl : string ): Promise <UnityLoaderConfig > {
147- let result: AxiosResponse <UnityLoaderConfig >;
145+ export async function fetchLoaderConfig(
146+ baseUrl : string
147+ ): Promise <UnityLoaderConfig > {
148+ // set the URL of where we expect the loader config to be and disable caching
149+ const url = ` ${baseUrl }/build.json?t=${new Date ().getTime ()} ` ;
148150
149- try {
150- // this disables caching!
151- const url = ` ${baseUrl }/build.json?t=${new Date ().getTime ()} ` ;
151+ let response: Response | undefined ;
152152
153- result = await axios .get <UnityLoaderConfig >(url );
153+ // network or request error
154+ try {
155+ response = await window .fetch (url , { method: ' GET' });
154156 } catch (ex ) {
155- // network or request error
156157 throw new Error (' unable to load build info' );
157158 }
158159
159- const { status, data } = result ;
160-
161160 // invalid response
162- if (status < 200 || status >= 400 ) {
163- throw new Error (' unable to load build info' );
164- }
161+ if (! response || ! response .ok ) throw new Error (' unable to load build info' );
162+
163+ // force the type we expect
164+ const data = (await response .json ()) as UnityLoaderConfig ;
165165
166166 return {
167167 loaderUrl: ` ${baseUrl }/${data .loaderUrl } ` ,
0 commit comments