diff --git a/next.config.js b/next.config.js index fb3b1a2..ca3432a 100644 --- a/next.config.js +++ b/next.config.js @@ -20,6 +20,7 @@ const customNextConfig = { MAPBOX_ACCESS_TOKEN: process.env.MAPBOX_ACCESS_TOKEN, POSTHOG_API_KEY: process.env.POSTHOG_API_KEY, SHOW_LINKS_TO_APP: process.env.SHOW_LINKS_TO_APP, + SITE_URL: process.env.SITE_URL, }, webpack(config) { config.module.rules.push({ diff --git a/src/pages/[projectID]/sitemap.xml.tsx b/src/pages/[projectID]/sitemap.xml.tsx index 28d9d1c..0b99b47 100644 --- a/src/pages/[projectID]/sitemap.xml.tsx +++ b/src/pages/[projectID]/sitemap.xml.tsx @@ -1,13 +1,13 @@ import type { GetServerSideProps } from 'next'; import { publicRuntimeConfig } from '../../runtimeConfig'; -const { API_URL } = publicRuntimeConfig; +const { API_URL, SITE_URL } = publicRuntimeConfig; const PROJECT_LINKS = ['/', '/map', '/compare', '/calculator', '/favorites']; -const generateSiteMap = (host: string, projectId: string, rspos: string[]) => { +const generateSiteMap = (projectId: string, rspos: string[]) => { const wrapURLWithTag = (url: string) => `${url}`; - const getFullUrl = (path: string) => `https://${host}/app/${projectId}${path}`; + const getFullUrl = (path: string) => `${SITE_URL}/app/${projectId}${path}`; const getSchoolPath = (rspo: string) => `/school/${rspo}`; return ` @@ -19,8 +19,7 @@ const generateSiteMap = (host: string, projectId: string, rspos: string[]) => { `; }; -export const getServerSideProps: GetServerSideProps = async ({ params, res, req }) => { - const host = req.headers.host as string; +export const getServerSideProps: GetServerSideProps = async ({ params, res }) => { const projectId = params?.projectID as string; const schoolsForProject = await fetch( @@ -28,7 +27,7 @@ export const getServerSideProps: GetServerSideProps = async ({ params, res, req ).then((r) => r.json()); const rspos = schoolsForProject.map((school) => school.rspo); - const sitemap = generateSiteMap(host, projectId, rspos); + const sitemap = generateSiteMap(projectId, rspos); res.setHeader('Content-Type', 'text/xml'); res.write(sitemap); diff --git a/src/runtimeConfig.ts b/src/runtimeConfig.ts index eaaa8e3..0af971f 100644 --- a/src/runtimeConfig.ts +++ b/src/runtimeConfig.ts @@ -9,6 +9,7 @@ export interface IPublicRuntimeConfig { MAPBOX_ACCESS_TOKEN: string; POSTHOG_API_KEY: string; SHOW_LINKS_TO_APP: string; + SITE_URL: string; } const emptyPublicRuntimeConfig: IPublicRuntimeConfig = { @@ -19,6 +20,7 @@ const emptyPublicRuntimeConfig: IPublicRuntimeConfig = { MAPBOX_ACCESS_TOKEN: '', POSTHOG_API_KEY: '', SHOW_LINKS_TO_APP: '', + SITE_URL: '', }; export const isFeatureFlagEnabled = (flagValue: string) => flagValue === 'true';