Skip to content

Sitemap await not... well, waiting... #141

@petethered

Description

@petethered

I'm trying to convert a SSG to SSR and found your extension which has been solving some of my sitemap issues. Thanks!

That being said, I'm running into issues trying to pull a list of ids to include in the sitemap for

During build, the await for fetch doesn't seem to be waiting.

[id].astro

import { fetchIds } from "../../data/items";
import sitemap from 'sitemap-ext:config';
sitemap(async ({ addToSitemap }) => {
  console.log("PreFetch");
  const ids = await fetchIds();
  console.log(ids);
  addToSitemap(
    ids?.data?.ids?.map((post) => ({
      id: post,
    }))
  );
});

items.ts

  try {
    console.log(`http://server/staticGenerator/items?allId=1`);
    const response = await fetch(`http://server/staticGenerator/items?allId=1`);
    console.log("Res: ", response);
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    const data = await response.json();
    return data;
  } catch (error) {
    console.error("Error", error);
    return {};
  }
};

Running build shows the "PreFetch", and the url in the console log, but nothing happens... the request isn't made.

Mind telling me what I'm missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions