最新版的 Shiro 已兼容的 leetcode 的卡片,但是因為 leetcode 的 api 需要後台獲取數據,這裡使用 mx-space 的雲函數來嫁接請求
為什麼要彎彎繞繞,不直接在服務端獲取數據後渲染,好像是渲染 markdown 的邏輯是客戶端,所以獲取數據也是在客戶端進行,無法利用 ssr 的優勢
先記錄一下吧,方便後續遷移
export default async function handler(ctx: Context) {
const requestBody =ctx.req.body
// 通用的 GraphQL 請求函數
const response = await fetch('https://leetcode.cn/graphql/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody),
});
if (!response.ok) {
throw new Error('Failed to fetch data from LeetCode API');
}
return await response.json();
}
雲函數配置信息
此文由 Mix Space 同步更新至 xLog
原始鏈接為 https://me.liuyaowen.cn/posts/codenotes/20241013