Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass app load context to export sitemap function #6

Open
fedeya opened this issue Mar 16, 2023 · 2 comments · May be fixed by #73
Open

pass app load context to export sitemap function #6

fedeya opened this issue Mar 16, 2023 · 2 comments · May be fixed by #73

Comments

@fedeya
Copy link
Owner

fedeya commented Mar 16, 2023

can be helpful get the loader context in the generateEntries for cloudflare kv, dependency injection, etc

@fedeya
Copy link
Owner Author

fedeya commented Mar 17, 2023

this not be possible because in the remix code each server platform package send the app load context in a handleLoader or handleAction never sended to the entry.server.ts

@fedeya fedeya closed this as completed Mar 17, 2023
@fedeya fedeya reopened this Aug 27, 2023
@fedeya
Copy link
Owner Author

fedeya commented Aug 28, 2023

Looks like the AppLoadContext is being sent to handleRequest in the entry.server as the last argument in the new express starter

export default function handleRequest(
  request: Request,
  responseStatusCode: number,
  responseHeaders: Headers,
  remixContext: EntryContext,
  loadContext: AppLoadContext // <- Here
) {
  if (isSitemapUrl(request)) {
    return sitemap(request, remixContext)
  }

  return isbot(request.headers.get("user-agent"))
    ? handleBotRequest(
      request,
      responseStatusCode,
      responseHeaders,
      remixContext
    )
    : handleBrowserRequest(
      request,
      responseStatusCode,
      responseHeaders,
      remixContext
    );
}

Now that can be sent throught sitemap response function and getted as a property in the export sitemap function for the people to use the AppLoadContext like a dependency injection or use features like kv in Cloudflare

example:

export const sitemap: SitemapFunction = async ({ context }) => {
  const posts = await context.api.posts.list();
  
  return posts.map(post => ({
    loc: `/posts/${post.slug}`
  }));
}

@fedeya fedeya changed the title pass app load context to generateEntries pass app load context to export sitemap function Aug 28, 2023
@sgammon sgammon linked a pull request Nov 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant