Updated handling of env vars.

This commit is contained in:
Mike Cao 2024-05-12 23:15:49 -07:00
parent f42a99cf7e
commit 98a0a83ccf
13 changed files with 29 additions and 25 deletions

View File

@ -3,19 +3,19 @@ require('dotenv').config();
const path = require('path');
const pkg = require('./package.json');
const basePath = process.env.BASE_PATH || '';
const collectApiEndpoint = process.env.COLLECT_API_ENDPOINT || '';
const cloudMode = process.env.CLOUD_MODE || '';
const cloudUrl = process.env.CLOUD_URL || '';
const defaultLocale = process.env.DEFAULT_LOCALE || '';
const disableLogin = process.env.DISABLE_LOGIN || '';
const disableUI = process.env.DISABLE_UI || '';
const forceSSL = process.env.FORCE_SSL || '';
const frameAncestors = process.env.ALLOWED_FRAME_URLS || '';
const privateMode = process.env.PRIVATE_MODE || '';
const shareUrlHost = process.env.SHARE_HOST_URL || '';
const trackerScriptHost = process.env.TRACKER_SCRIPT_HOST || '';
const trackerScriptName = process.env.TRACKER_SCRIPT_NAME || '';
const basePath = process.env.BASE_PATH;
const collectApiEndpoint = process.env.COLLECT_API_ENDPOINT;
const cloudMode = process.env.CLOUD_MODE;
const cloudUrl = process.env.CLOUD_URL;
const defaultLocale = process.env.DEFAULT_LOCALE;
const disableLogin = process.env.DISABLE_LOGIN;
const disableUI = process.env.DISABLE_UI;
const forceSSL = process.env.FORCE_SSL;
const frameAncestors = process.env.ALLOWED_FRAME_URLS;
const privateMode = process.env.PRIVATE_MODE;
const shareUrlHost = process.env.SHARE_URL_HOST;
const trackerScriptHost = process.env.TRACKER_SCRIPT_HOST;
const trackerScriptName = process.env.TRACKER_SCRIPT_NAME;
const contentSecurityPolicy = [
`default-src 'self'`,

View File

@ -27,7 +27,7 @@ export function App({ children }) {
{children}
<UpdateNotice user={user} config={config} />
{process.env.NODE_ENV === 'production' && !pathname.includes('/share/') && (
<Script src={`${process.env.basePath}/telemetry.js`} />
<Script src={`${process.env.basePath || ''}/telemetry.js`} />
)}
</>
);

View File

@ -80,7 +80,7 @@ export function TestConsole({ websiteId }: { websiteId: string }) {
<Script
async
data-website-id={websiteId}
src={`${process.env.basePath}/script.js`}
src={`${process.env.basePath || ''}/script.js`}
data-cache="true"
/>
<div className={styles.actions}>

View File

@ -13,7 +13,7 @@ export function RealtimeCountries({ data }) {
({ x: code }) => (
<span className={classNames(locale, styles.row)}>
<img
src={`${process.env.basePath}/images/flags/${code?.toLowerCase() || 'xx'}.png`}
src={`${process.env.basePath || ''}/images/flags/${code?.toLowerCase() || 'xx'}.png`}
alt={code}
/>
{countryNames[code]}

View File

@ -10,7 +10,7 @@ export function useCountryNames(locale: string) {
const [list, setList] = useState(countryNames[locale] || enUS);
async function loadData(locale: string) {
const { data } = await httpGet(`${process.env.basePath}/intl/country/${locale}.json`);
const { data } = await httpGet(`${process.env.basePath || ''}/intl/country/${locale}.json`);
if (data) {
countryNames[locale] = data;

View File

@ -10,7 +10,7 @@ export function useLanguageNames(locale) {
const [list, setList] = useState(languageNames[locale] || enUS);
async function loadData(locale) {
const { data } = await httpGet(`${process.env.basePath}/intl/language/${locale}.json`);
const { data } = await httpGet(`${process.env.basePath || ''}/intl/language/${locale}.json`);
if (data) {
languageNames[locale] = data;

View File

@ -19,7 +19,9 @@ export function useLocale() {
const dateLocale = getDateLocale(locale);
async function loadMessages(locale: string) {
const { ok, data } = await httpGet(`${process.env.basePath}/intl/messages/${locale}.json`);
const { ok, data } = await httpGet(
`${process.env.basePath || ''}/intl/messages/${locale}.json`,
);
if (ok) {
messages[locale] = data;

View File

@ -11,7 +11,7 @@ export function BrowsersTable(props: MetricsTableProps) {
return (
<FilterLink id="browser" value={browser} label={formatBrowser(browser)}>
<img
src={`${process.env.basePath}/images/browsers/${browser || 'unknown'}.png`}
src={`${process.env.basePath || ''}/images/browsers/${browser || 'unknown'}.png`}
alt={browser}
width={16}
height={16}

View File

@ -20,7 +20,7 @@ export function CitiesTable(props: MetricsTableProps) {
<FilterLink id="city" value={city} label={renderLabel(city, country)}>
{country && (
<img
src={`${process.env.basePath}/images/flags/${country?.toLowerCase() || 'xx'}.png`}
src={`${process.env.basePath || ''}/images/flags/${country?.toLowerCase() || 'xx'}.png`}
alt={country}
/>
)}

View File

@ -27,7 +27,7 @@ export function CountriesTable({
label={formatCountry(code)}
>
<img
src={`${process.env.basePath}/images/flags/${code?.toLowerCase() || 'xx'}.png`}
src={`${process.env.basePath || ''}/images/flags/${code?.toLowerCase() || 'xx'}.png`}
alt={code}
/>
</FilterLink>

View File

@ -11,7 +11,9 @@ export function DevicesTable(props: MetricsTableProps) {
return (
<FilterLink id="device" value={labels[device] && device} label={formatDevice(device)}>
<img
src={`${process.env.basePath}/images/device/${device?.toLowerCase() || 'unknown'}.png`}
src={`${process.env.basePath || ''}/images/device/${
device?.toLowerCase() || 'unknown'
}.png`}
alt={device}
width={16}
height={16}

View File

@ -20,7 +20,7 @@ export function RegionsTable(props: MetricsTableProps) {
return (
<FilterLink id="region" className={locale} value={code} label={renderLabel(code, country)}>
<img
src={`${process.env.basePath}/images/flags/${country?.toLowerCase() || 'xx'}.png`}
src={`${process.env.basePath || ''}/images/flags/${country?.toLowerCase() || 'xx'}.png`}
alt={code}
/>
</FilterLink>

View File

@ -54,7 +54,7 @@ export function WorldMap({ data = [], className }: { data?: any[]; className?: s
>
<ComposableMap projection="geoMercator">
<ZoomableGroup zoom={0.8} minZoom={0.7} center={[0, 40]}>
<Geographies geography={`${process.env.basePath}${MAP_FILE}`}>
<Geographies geography={`${process.env.basePath || ''}${MAP_FILE}`}>
{({ geographies }) => {
return geographies.map(geo => {
const code = ISO_COUNTRIES[geo.id];