The latest version of Shiro already supports LeetCode cards, but because LeetCode's API requires data to be fetched on the backend, this setup uses an mx-space cloud function to bridge the request
Why go through all this instead of simply fetching the data on the server and rendering it there? It seems the Markdown rendering logic runs on the client, so the data is fetched on the client as well, which means we can't take advantage of SSR.
Let's jot this down for now so it's easier to migrate later.
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();
}
Cloud Function Configuration

image-20241013231352625