Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 24, 2025

This PR extracts the sitemap route handling logic from core/app/sitemap.xml/route.ts into a new reusable package @bigcommerce/catalyst-sitemap that can be trivially included as a route handler with configurable parameters.

Problem

The sitemap route handler was tightly coupled to the core application with hardcoded dependencies on locale configuration and client setup. This made it difficult to:

  • Reuse the sitemap functionality in other Catalyst applications
  • Test the sitemap logic independently
  • Configure different environments with varying hostname/protocol requirements
  • Maintain the complex URL rewriting logic in multiple places

Solution

Created a new package @bigcommerce/catalyst-sitemap that provides a createSitemapHandler function accepting configuration for:

  • Client instance: Any BigCommerce client with sitemap methods
  • Channel ID resolution: Flexible function to determine channel ID from request context
  • Hostname override: Optional hostname for sitemap URL rewriting
  • Protocol override: Optional protocol (http/https) for sitemap URL rewriting

Usage

Before (76 lines of route logic):

export const GET = async (request: Request) => {
  // Complex sitemap handling logic with hardcoded dependencies
  const channelId = getChannelIdFromLocale(defaultLocale);
  // ... 70+ lines of sitemap processing
};

After (8 lines using the package):

import { createSitemapHandler } from '@bigcommerce/catalyst-sitemap';

export const GET = createSitemapHandler({
  client,
  getChannelId: async () => getChannelIdFromLocale(defaultLocale),
});

Key Benefits

  • 89% code reduction in the core route file (76 → 8 lines)
  • Reusable across projects with simple configuration
  • Environment agnostic - works with any BigCommerce client setup
  • Flexible configuration for different hostname/protocol requirements
  • Preserved functionality - handles both sitemap index and individual sitemaps with URL normalization
  • Clean interface following established Catalyst package patterns

Implementation Details

The package preserves all existing functionality:

  • Serves BigCommerce sitemap index with URL rewriting to match application domain
  • Handles individual sitemap requests with type and page parameters
  • Validates required parameters and provides appropriate error responses
  • Maintains XML content-type headers and status code pass-through

The interface is designed to be framework-agnostic while optimized for Next.js App Router usage.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • googlechromelabs.github.io
    • Triggering command: node install.mjs (dns block)
  • https://storage.googleapis.com/chrome-for-testing-public/139.0.7258.138/linux64/chrome-linux64.zip
    • Triggering command: node install.mjs (http block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link

vercel bot commented Aug 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
catalyst-b2b Error Error Aug 24, 2025 3:39am
catalyst-canary Error Error Comment Aug 24, 2025 3:39am
3 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
catalyst Ignored Ignored Aug 24, 2025 3:39am
catalyst-au Ignored Ignored Aug 24, 2025 3:39am
catalyst-uk Ignored Ignored Aug 24, 2025 3:39am

Copy link

changeset-bot bot commented Aug 24, 2025

⚠️ No Changeset found

Latest commit: 18b7354

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Copilot Copilot AI changed the title [WIP] Extract the handling of the /sitemap.xml route into a package which is trivially included as a route handler, accepting necessary configuration like store hash and channel ID, hostname, and protocol from the environment and/or application as relevant Extract sitemap route handling into reusable @bigcommerce/catalyst-sitemap package Aug 24, 2025
@Copilot Copilot AI requested a review from bookernath August 24, 2025 03:40
Copilot finished work on behalf of bookernath August 24, 2025 03:40
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 this pull request may close these issues.

2 participants