app.get("/news/top", async (ctx) => {
try {
const { KV } = getRequestContext().env;
const keys = ["business", "politics", "sports", "tech", "business"]; // Changed the last key to "top"
const promises = keys.map((key) => KV.get(key));
const [business_news, politics_news, sports_news, tech_news, top_news] =
await Promise.all(promises);
const news = {
business: JSON.parse(business_news || "null"),
politics: JSON.parse(politics_news || "null"),
sports: JSON.parse(sports_news || "null"),
tech: JSON.parse(tech_news || "null"),
top: JSON.parse(top_news || "null"),
};
return ctx.json(news);
} catch (error) {
console.error("error: ", error);
return ctx.json({ message: "Internal server error" });
}
});
app.get("/news/top", async (ctx) => {
try {
const { KV } = getRequestContext().env;
const keys = ["business", "politics", "sports", "tech", "business"]; // Changed the last key to "top"
const promises = keys.map((key) => KV.get(key));
const [business_news, politics_news, sports_news, tech_news, top_news] =
await Promise.all(promises);
const news = {
business: JSON.parse(business_news || "null"),
politics: JSON.parse(politics_news || "null"),
sports: JSON.parse(sports_news || "null"),
tech: JSON.parse(tech_news || "null"),
top: JSON.parse(top_news || "null"),
};
return ctx.json(news);
} catch (error) {
console.error("error: ", error);
return ctx.json({ message: "Internal server error" });
}
});