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

View File

@ -27,7 +27,7 @@ export function App({ children }) {
{children} {children}
<UpdateNotice user={user} config={config} /> <UpdateNotice user={user} config={config} />
{process.env.NODE_ENV === 'production' && !pathname.includes('/share/') && ( {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 <Script
async async
data-website-id={websiteId} data-website-id={websiteId}
src={`${process.env.basePath}/script.js`} src={`${process.env.basePath || ''}/script.js`}
data-cache="true" data-cache="true"
/> />
<div className={styles.actions}> <div className={styles.actions}>

View File

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

View File

@ -10,7 +10,7 @@ export function useCountryNames(locale: string) {
const [list, setList] = useState(countryNames[locale] || enUS); const [list, setList] = useState(countryNames[locale] || enUS);
async function loadData(locale: string) { 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) { if (data) {
countryNames[locale] = data; countryNames[locale] = data;

View File

@ -10,7 +10,7 @@ export function useLanguageNames(locale) {
const [list, setList] = useState(languageNames[locale] || enUS); const [list, setList] = useState(languageNames[locale] || enUS);
async function loadData(locale) { 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) { if (data) {
languageNames[locale] = data; languageNames[locale] = data;

View File

@ -19,7 +19,9 @@ export function useLocale() {
const dateLocale = getDateLocale(locale); const dateLocale = getDateLocale(locale);
async function loadMessages(locale: string) { 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) { if (ok) {
messages[locale] = data; messages[locale] = data;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -54,7 +54,7 @@ export function WorldMap({ data = [], className }: { data?: any[]; className?: s
> >
<ComposableMap projection="geoMercator"> <ComposableMap projection="geoMercator">
<ZoomableGroup zoom={0.8} minZoom={0.7} center={[0, 40]}> <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 }) => { {({ geographies }) => {
return geographies.map(geo => { return geographies.map(geo => {
const code = ISO_COUNTRIES[geo.id]; const code = ISO_COUNTRIES[geo.id];