Files
api/app/utils.ts
Alexis Tyler 4e1b0bd72c chore: lint
2021-01-28 15:45:14 +10:30

31 lines
837 B
TypeScript

import fetch from 'cross-fetch';
import * as Sentry from '@sentry/node';
import { MOTHERSHIP_GRAPHQL_LINK } from './consts';
import { CachedServer } from './cache';
export const getServers = async (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, errors } = await response.json();
if (errors) {
return new Error(errors[0].message);
}
return data.servers as Promise<CachedServer[]>;
})
.catch(error => {
Sentry.captureException(error);
return error;
});