Include site origin in build

This commit is contained in:
Jake Archibald
2021-07-27 11:30:58 +01:00
parent 3d4c62fede
commit 0ed7ef842f
3 changed files with 22 additions and 5 deletions

View File

@@ -56,3 +56,17 @@ export function escapeStyleScriptContent(str: string): string {
.replace(/<style/g, '<\\style')
.replace(/<\/style/g, '<\\/style');
}
/**
* Origin of the site, depending on the environment.
*/
export const siteOrigin = (() => {
if (process.env.DEV_PORT) return `http://localhost:${process.env.DEV_PORT}`;
// https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
if (process.env.CONTEXT === 'production') return 'https://squoosh.app';
if (process.env.DEPLOY_PRIME_URL) return process.env.DEPLOY_PRIME_URL;
console.warn(
'Unable to determine site origin, defaulting to https://squoosh.app',
);
return 'https://squoosh.app';
})();