Skip to content

Instantly share code, notes, and snippets.

@NuroDev
Created July 19, 2022 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NuroDev/953c49714456e2fed2afa65a08b513c6 to your computer and use it in GitHub Desktop.
Save NuroDev/953c49714456e2fed2afa65a08b513c6 to your computer and use it in GitHub Desktop.
🚨 Planetscale Incidents ─ TypeScript Planetscale status API proxy endpoint
// api/database/incidents.ts
interface Incident {
id: string;
url: string;
name: string;
}
interface UnresolvedIncidentsResponse {
page: {
id: string;
name: string;
time_zone: string;
updated_at: Date;
url: string;
};
incidents: Array<Incident>;
}
export default async function handler() {
try {
const res = await fetch(
'https://www.planetscalestatus.com/api/v2/incidents/unresolved.json'
);
const json: UnresolvedIncidentsResponse = await res.json();
const incident = json?.incidents?.[0]
? {
...json?.incidents?.[0],
url: `https://www.planetscalestatus.com/incidents/${json?.incidents?.[0].id}`,
}
: null;
return new Response(JSON.stringify(incident), {
status: 200,
headers: {
'cache-control': 's-maxage=1, stale-while-revalidate',
},
});
} catch ({ status = 500, message = 'Internal Server Error' }) {
return new Response(JSON.stringify({ message }), {
status: status as number,
});
}
}
export const config = {
runtime: 'experimental-edge',
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment