Files
api/app/utils.ts
2020-10-04 13:37:21 +10:30

24 lines
767 B
TypeScript

import * as Sentry from '@sentry/node';
import { MOTHERSHIP_GRAPHQL_LINK } from './consts';
import { CachedServer } from './cache';
export const getServers = (apiKey: string) => fetch(MOTHERSHIP_GRAPHQL_LINK, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query: 'query($apiKey: String!) { servers @auth(apiKey: $apiKey) { owner { username url avatar } guid apikey name status wanip lanip localurl remoteurl } }',
variables: {
apiKey
}
})
})
.then(async response => {
const data = await response.json();
return data.servers as Promise<CachedServer[]>;
})
.catch(error => {
Sentry.captureException(error);
});