mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36:58 +00:00
refactor baseUrl to consider vercel prod env and existing env var for prod URL (TWITTER_SITE)
This commit is contained in:
parent
610b0e8692
commit
77035c9362
@ -3,16 +3,14 @@ import { GeistSans } from 'geist/font';
|
||||
import { ensureStartsWith } from 'lib/utils';
|
||||
import { ReactNode, Suspense } from 'react';
|
||||
import './globals.css';
|
||||
import { BASE_URL } from 'lib/constants';
|
||||
|
||||
const { TWITTER_CREATOR, TWITTER_SITE, SITE_NAME } = process.env;
|
||||
const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL
|
||||
? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
|
||||
: 'http://localhost:3000';
|
||||
const twitterCreator = TWITTER_CREATOR ? ensureStartsWith(TWITTER_CREATOR, '@') : undefined;
|
||||
const twitterSite = TWITTER_SITE ? ensureStartsWith(TWITTER_SITE, 'https://') : undefined;
|
||||
|
||||
export const metadata = {
|
||||
metadataBase: new URL(baseUrl),
|
||||
metadataBase: new URL(BASE_URL),
|
||||
title: {
|
||||
default: SITE_NAME!,
|
||||
template: `%s | ${SITE_NAME}`
|
||||
|
@ -1,6 +1,4 @@
|
||||
const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL
|
||||
? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
|
||||
: 'http://localhost:3000';
|
||||
import { BASE_URL } from "lib/constants";
|
||||
|
||||
export default function robots() {
|
||||
return {
|
||||
@ -9,7 +7,7 @@ export default function robots() {
|
||||
userAgent: '*'
|
||||
}
|
||||
],
|
||||
sitemap: `${baseUrl}/sitemap.xml`,
|
||||
host: baseUrl
|
||||
sitemap: `${BASE_URL}/sitemap.xml`,
|
||||
host: BASE_URL
|
||||
};
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { BASE_URL } from 'lib/constants';
|
||||
import { getCollections, getPages, getProducts } from 'lib/shopify';
|
||||
import { validateEnvironmentVariables } from 'lib/utils';
|
||||
import { MetadataRoute } from 'next';
|
||||
@ -7,35 +8,31 @@ type Route = {
|
||||
lastModified: string;
|
||||
};
|
||||
|
||||
const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL
|
||||
? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
|
||||
: 'http://localhost:3000';
|
||||
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
validateEnvironmentVariables();
|
||||
|
||||
const routesMap = [''].map((route) => ({
|
||||
url: `${baseUrl}${route}`,
|
||||
url: `${BASE_URL}${route}`,
|
||||
lastModified: new Date().toISOString()
|
||||
}));
|
||||
|
||||
const collectionsPromise = getCollections().then((collections) =>
|
||||
collections.map((collection) => ({
|
||||
url: `${baseUrl}${collection.path}`,
|
||||
url: `${BASE_URL}${collection.path}`,
|
||||
lastModified: collection.updatedAt
|
||||
}))
|
||||
);
|
||||
|
||||
const productsPromise = getProducts({}).then((products) =>
|
||||
products.map((product) => ({
|
||||
url: `${baseUrl}/product/${product.handle}`,
|
||||
url: `${BASE_URL}/product/${product.handle}`,
|
||||
lastModified: product.updatedAt
|
||||
}))
|
||||
);
|
||||
|
||||
const pagesPromise = getPages().then((pages) =>
|
||||
pages.map((page) => ({
|
||||
url: `${baseUrl}/${page.handle}`,
|
||||
url: `${BASE_URL}/${page.handle}`,
|
||||
lastModified: page.updatedAt
|
||||
}))
|
||||
);
|
||||
|
@ -29,3 +29,10 @@ export const TAGS = {
|
||||
export const HIDDEN_PRODUCT_TAG = 'nextjs-frontend-hidden';
|
||||
export const DEFAULT_OPTION = 'Default Title';
|
||||
export const SHOPIFY_GRAPHQL_API_ENDPOINT = '/api/2023-01/graphql.json';
|
||||
|
||||
export const BASE_URL =
|
||||
process.env.NEXT_PUBLIC_VERCEL_ENV === 'production' && process.env.TWITTER_SITE
|
||||
? process.env.TWITTER_SITE
|
||||
: process.env.NEXT_PUBLIC_VERCEL_URL
|
||||
? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
|
||||
: 'http://localhost:3000';
|
||||
|
Loading…
x
Reference in New Issue
Block a user