website/src/routes/pubnix/+page.server.ts
2023-02-03 19:55:33 +02:00

27 lines
511 B
TypeScript

import type { PageServerLoad } from "./$types";
export const load = (async ({ fetch }) => {
const meta = {
title: "Pubnix"
};
try {
const request = await fetch("https://publapi.p.projectsegfau.lt/users");
if (request.ok) {
return {
users: await request.json(),
...meta
};
} else {
return {
error: true,
message: "Error: " + request.status,
...meta
};
}
} catch (err) {
return { error: true, message: "Error: " + err, ...meta };
}
}) satisfies PageServerLoad;