Skip to content

Commit

Permalink
update api-status to use reusable func
Browse files Browse the repository at this point in the history
  • Loading branch information
ehanahamed committed Feb 1, 2025
1 parent 41ad080 commit f2428c6
Showing 1 changed file with 7 additions and 62 deletions.
69 changes: 7 additions & 62 deletions web/src/routes/api-status/+page.server.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,13 @@
import { env } from "$env/dynamic/private";
import apiStatusConfig from "../../../api-status.config";
import checkApiStatus from "$lib/checkApiStatus.server";

export async function load({ cookies }) {
try {
let rawApiRes = await fetch(env.API_URL + "/graphql", {
method: "POST",
headers: {
"Authorization": "Bearer " + cookies.get("auth"),
"Content-Type": "application/json"
},
body: JSON.stringify({
query: `query {
authed
authedUser {
id
username
display_name
auth_type
oauth_google_email
}
dbConnectionStatus {
connectionUp
}
cronStatus {
errorCount
anyEnabled
}
}`
})
});
try {
let apiRes = await rawApiRes.json()
if (apiRes && apiRes.data) {
return {
authed: apiRes?.data?.authed ?? false,
authedUser: apiRes?.data?.authedUser,
apiUp: true,
dbConnectionUp: apiRes.data?.dbConnectionStatus?.connectionUp ?? false,
apiCronErrorCount: apiRes.data?.cronStatus?.errorCount,
apiCronAnyEnabled: apiRes.data?.cronStatus?.anyEnabled,
config: apiStatusConfig
};
} else {
return {
authed: false,
apiUp: true,
apiResponseErrorNoData: true,
config: apiStatusConfig
}
}
} catch (error) {
return {
authed: false,
apiUp: true,
apiResponseErrorNotJSON: true,
config: apiStatusConfig
}
}
} catch (error) {
console.error(error);
return {
authed: false,
apiUp: false,
config: apiStatusConfig
}
return {
...await checkApiStatus({
authCookie: cookies.get("auth"),
API_URL: env.API_URL
}),
config: apiStatusConfig
}
}

0 comments on commit f2428c6

Please sign in to comment.