webcompile/src/routes/blog/fetchGhost.ts

23 lines
683 B
TypeScript
Raw Normal View History

2023-01-25 22:41:11 +05:30
import { env } from "$env/dynamic/private";
import axios from "axios";
import { Agent } from "https";
const agent = new Agent({
family: 4
});
const fetchGhost = async (action: string, additional?: string ) => {
try {
const request = await axios(env.GHOST_URL + "/ghost/api/content/" + action + "/?key=" + env.GHOST_API_KEY + "&include=authors,tags&limit=all&formats=html,plaintext" + (additional ? additional : ""), { httpsAgent: agent });
if (request.status === 200) {
return request.data;
} else {
return { error: true, message: "Error: " + request.status };
}
} catch (err) {
return { error: true, message: "Error: " + err };
}
}
export default fetchGhost;