@@ -135,33 +135,33 @@ In order to create a fetchable build config that contains all required keys for
135
135
136
136
```
137
137
138
- Take the following example using ` axios ` :
138
+ Take the following example using ` fetch ` :
139
139
140
140
` unity-api.ts `
141
141
142
142
``` ts
143
- import axios , { AxiosResponse } from ' axios' ;
144
143
import { UnityLoaderConfig } from ' react-unity-renderer' ;
145
144
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 ()} ` ;
148
150
149
- try {
150
- // this disables caching!
151
- const url = ` ${baseUrl }/build.json?t=${new Date ().getTime ()} ` ;
151
+ let response: Response | undefined ;
152
152
153
- result = await axios .get <UnityLoaderConfig >(url );
153
+ // network or request error
154
+ try {
155
+ response = await window .fetch (url , { method: ' GET' });
154
156
} catch (ex ) {
155
- // network or request error
156
157
throw new Error (' unable to load build info' );
157
158
}
158
159
159
- const { status, data } = result ;
160
-
161
160
// 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 ;
165
165
166
166
return {
167
167
loaderUrl: ` ${baseUrl }/${data .loaderUrl } ` ,
0 commit comments