fix: status is broken

This commit is contained in:
dvelo 2025-02-06 18:33:59 -06:00
parent f2feb1ae73
commit 17f444fbf4

@ -30,32 +30,33 @@
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
export default async function handler( export default async function handler(
req: NextApiRequest, req: NextApiRequest,
res: NextApiResponse res: NextApiResponse,
) { ) {
const betterStackResult = await fetch( const betterStackResult = await fetch(
`https://uptime.betterstack.com/api/v2/status-pages/${process.env.BS_STATUS_PAGE}/status-reports`, `https://uptime.betterstack.com/api/v2/status-pages/${process.env.BS_STATUS_PAGE}/status-reports`,
{ headers: { Authorization: `Bearer ${process.env.BS_TOKEN}` } } { headers: { Authorization: `Bearer ${process.env.BS_TOKEN}` } },
); );
const betterStackURL = await fetch( const betterStackURL = await fetch(
`https://uptime.betterstack.com/api/v2/status-pages/${process.env.BS_STATUS_PAGE}`, `https://uptime.betterstack.com/api/v2/status-pages/${process.env.BS_STATUS_PAGE}`,
{ headers: { Authorization: `Bearer ${process.env.BS_TOKEN}` } } { headers: { Authorization: `Bearer ${process.env.BS_TOKEN}` } },
); );
const result = await betterStackResult.json(); const result = await betterStackResult.json();
const url = await betterStackURL.json(); const url = await betterStackURL.json();
const filtered = result.data.filter( const filtered = result.data.filter(
(c: any) => (c: any) =>
c.attributes.ends_at === null && c.attributes.ends_at === null &&
c.attributes.affected_resources.filter( c.attributes.affected_resources.filter(
(v: any) => (v: any) =>
v.status_page_resource_id === process.env.BS_STATUS_MAIN_WEBSITE v.status_page_resource_id === process.env.BS_STATUS_MAIN_WEBSITE &&
).length > 0 v.status !== "resolved",
); ).length > 0,
);
res.status(200).send({ res.status(200).send({
url: url.data.attributes.custom_domain, url: url.data.attributes.custom_domain,
incidents: filtered, incidents: filtered,
}); });
} }