Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/real-ladybugs-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": minor
---

Added /sitemap.xml as a proxy to hosted BigCommerce sitemap
27 changes: 27 additions & 0 deletions core/app/robots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { MetadataRoute } from 'next';

// Disallow routes that have no SEO value or should not be indexed
const disallow = ['/cart', '/account'];

// Robots.txt config https://nextjs.org/docs/app/api-reference/file-conventions/metadata/robots#generate-a-robots-file
const robotsConfig: MetadataRoute.Robots = {
rules: [
{
userAgent: '*',
allow: ['/'],
disallow,
},
],
};

// Infer base URL from environment variables
const baseUrl = process.env.PRODUCTION_BASE_URL || process.env.NEXTAUTH_URL;

// Set sitemap URL if base URL is defined, as sitemap URL must be an absolute URL
if (baseUrl) {
robotsConfig.sitemap = `${baseUrl}/sitemap.xml`;
}

export default function robots(): MetadataRoute.Robots {
return robotsConfig;
}
2 changes: 0 additions & 2 deletions core/app/robots.txt

This file was deleted.

14 changes: 14 additions & 0 deletions core/app/sitemap.xml/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable check-file/folder-naming-convention */
/*
* Proxy to the existing BigCommerce sitemap index on the canonical URL
*/

const storeHash = process.env.BIGCOMMERCE_STORE_HASH;
const channelId = process.env.BIGCOMMERCE_CHANNEL_ID;
const canonicalDomain: string = process.env.BIGCOMMERCE_GRAPHQL_API_DOMAIN ?? 'mybigcommerce.com';

const remoteSitemapUrl = `https://store-${storeHash}-${channelId}.${canonicalDomain}/xmlsitemap.php`;

export const GET = async () => fetch(remoteSitemapUrl);

export const runtime = 'edge';
13 changes: 13 additions & 0 deletions core/app/xmlsitemap.php/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable check-file/folder-naming-convention */
import { permanentRedirect } from 'next/navigation';

/*
* This route is used to redirect the legacy Stencil sitemap that lives on /xmlsitemap.php
* to Catalyst's new location on /sitemap.xml
* This is for the benefit of websites who already have a sitemap submitted to Webmaster Tools
* on /xmlsitemap.php
*/

export const GET = () => permanentRedirect('/sitemap.xml');

export const runtime = 'edge';
6 changes: 5 additions & 1 deletion core/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export const config = {
* - _next/image (image optimization files)
* - _vercel (vercel internals, eg: web vitals)
* - favicon.ico (favicon file)
* - admin (admin panel)
* - sitemap.xml (sitemap route)
* - xmlsitemap.php (legacy sitemap route)
* - robots.txt (robots route)
*/
'/((?!api|admin|_next/static|_next/image|_vercel|favicon.ico).*)',
'/((?!api|admin|_next/static|_next/image|_vercel|favicon.ico|xmlsitemap.php|sitemap.xml|robots.txt).*)',
],
};