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

27 lines
650 B
TypeScript
Raw Normal View History

2022-11-10 00:12:34 +05:30
import type { PageServerLoad } from "./$types";
2023-01-25 22:41:11 +05:30
import axios from "axios";
import { Agent } from "https";
import { env } from "$env/dynamic/private";
2022-11-10 00:12:34 +05:30
2023-01-25 22:41:11 +05:30
const agent = new Agent({
family: 4
});
2023-01-25 22:41:11 +05:30
export const load = (async () => {
const meta = {
title: "Home",
description: "Open source development and hosted services."
}
2023-01-06 15:58:16 +05:30
2023-01-25 22:41:11 +05:30
try {
const res = await axios(env.KUMA_URL, { httpsAgent: agent });
2023-01-06 15:58:16 +05:30
2023-01-25 22:41:11 +05:30
if (res.status === 200) {
return { announcements: res.data, ...meta };
} else {
return { error: true, message: "Error: " + res.status };
}
2023-01-25 22:41:11 +05:30
} catch (err) {
return { error: true, message: "Error: " + err };
}
2023-01-25 22:41:11 +05:30
}) satisfies PageServerLoad;