Skip to content

Commit abc530a

Browse files
committed
Maybe blocked because of headers?
1 parent 62b9fd2 commit abc530a

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
1-
import { metaApi } from '$lib/api';
1+
import { PUBLIC_BACKEND_API_DOMAIN } from '$env/static/public';
2+
import { Configuration, MetaApi } from '$lib/api/internal/v1';
23

3-
export async function load({ setHeaders }): Promise<{ ok: false, error: string } | { ok: true, deviceCount: number }> {
4+
type ResponseType = Promise<{ ok: false; error: string } | { ok: true; deviceCount: number }>;
5+
6+
export async function load({ setHeaders }): ResponseType {
47
setHeaders({
5-
'cache-control': 'public, max-age=300'
6-
})
8+
'cache-control': 'public, max-age=300',
9+
});
10+
11+
let deviceCount: number;
12+
13+
try {
14+
const metaApi = new MetaApi(
15+
new Configuration({
16+
basePath: 'https://' + PUBLIC_BACKEND_API_DOMAIN,
17+
headers: {
18+
'User-Agent': 'OpenShockFrontend/1.0 (ServerSide)',
19+
},
20+
credentials: 'omit',
21+
})
22+
);
23+
24+
const { data } = await metaApi.publicGetOnlineDevicesStatistics();
25+
26+
deviceCount = data.devicesOnline;
27+
} catch (e) {
28+
console.error(e);
729

8-
const { data } = await metaApi.publicGetOnlineDevicesStatistics();
30+
return {
31+
ok: false,
32+
error: 'Failed to fetch device count',
33+
};
34+
}
935

10-
return { ok: true, deviceCount: data.devicesOnline };
36+
return { ok: true, deviceCount };
1137
}

0 commit comments

Comments
 (0)