gitdagray/next-js-course

Next12 update getPostsMeta and getPostsbyName due to unexpected behavior.

Opened this issue · 0 comments

Remove the Github api version as it seems it is deprecated and was giving unexpected results. Too lazy to make a pr. Here is the correct fetch calls.

export async function getPostsMeta(): Promise<Meta[] | undefined> {
  const blogPosts = await fetch(
    "https://api.github.com/repos/${user}/blogs/git/trees/main?recursive=1",
    {
      headers: {
        Accept: "application/vnd.github+json",
        Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
      },
    }
  );

export async function getPostByName(
  fileName: string
): Promise<BlogPost | undefined> {
  const post = await fetch(
    `https://raw.githubusercontent.com/${user}/blogs/main/${fileName}`,
    {
      headers: {
        Accept: "application/vnd.github+json",
        Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
      },
    }
  );