刘耀文

刘耀文

java开发者
github

Shiro 渲染leetcode卡片

最新版的 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();

}

云函数配置信息

image-20241013231352625

此文由 Mix Space 同步更新至 xLog
原始链接为 https://me.liuyaowen.cn/posts/codenotes/20241013


加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。