website/src/routes/pubnix/+page.server.ts

27 lines
511 B
TypeScript
Raw Normal View History

2023-01-07 22:59:58 +05:30
import type { PageServerLoad } from "./$types";
export const load = (async ({ fetch }) => {
2023-01-25 22:41:11 +05:30
const meta = {
title: "Pubnix"
2023-02-03 23:25:33 +05:30
};
2023-01-25 22:41:11 +05:30
2023-01-07 22:59:58 +05:30
try {
2023-01-25 22:41:11 +05:30
const request = await fetch("https://publapi.p.projectsegfau.lt/users");
2023-01-07 22:59:58 +05:30
if (request.ok) {
2023-01-25 22:41:11 +05:30
return {
users: await request.json(),
...meta
};
2023-01-07 22:59:58 +05:30
} else {
2023-02-03 23:25:33 +05:30
return {
error: true,
message: "Error: " + request.status,
...meta
};
2023-01-07 22:59:58 +05:30
}
} catch (err) {
2023-01-25 22:41:11 +05:30
return { error: true, message: "Error: " + err, ...meta };
2023-01-07 22:59:58 +05:30
}
2023-02-03 23:25:33 +05:30
}) satisfies PageServerLoad;