π Open source, privacy-first web analytics β a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
selfhosted: let users know if API_URL is not set
Blue Mouse4896e875507a
diff --git a/web/app/components/SelfhostedApiUrlBanner.tsx b/web/app/components/SelfhostedApiUrlBanner.tsxnew file mode 100644index 000000000..37560fe3c--- /dev/null+++ b/web/app/components/SelfhostedApiUrlBanner.tsx@@ -0,0 +1,74 @@+import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'+import { memo, useState } from 'react'+import { useTranslation } from 'react-i18next'++import { isSelfhosted, apiUrlUnprocessed } from '~/lib/constants'+import Modal from '~/ui/Modal'++const SelfhostedApiUrlBanner = () => {+ const { t } = useTranslation('common')+ const [showMoreInfoModal, setShowMoreInfoModal] = useState(false)++ if (!isSelfhosted || apiUrlUnprocessed) {+ return null+ }++ return (+ <>+ <div className='bg-yellow-400 dark:bg-yellow-500'>+ <div className='mx-auto max-w-7xl px-3 py-3 sm:px-6 lg:px-8'>+ <div className='flex flex-wrap items-center justify-between'>+ <div className='flex flex-1 items-center'>+ <span className='flex rounded-lg bg-yellow-600 p-2'>+ <ExclamationTriangleIcon className='h-6 w-6 text-white' aria-hidden='true' />+ </span>+ <p className='ml-3 truncate font-medium text-black'>Can't reach backend β check API_URL configuration</p>+ </div>+ <div className='order-3 mt-2 w-full shrink-0 sm:order-2 sm:mt-0 sm:w-auto'>+ <span+ onClick={() => setShowMoreInfoModal(true)}+ className='flex cursor-pointer items-center justify-center rounded-md bg-gray-50 px-4 py-2 text-sm font-medium text-yellow-600 hover:bg-yellow-50 dark:bg-slate-800 dark:text-gray-50 dark:hover:bg-slate-700'+ >+ {t('common.learnMore')}+ </span>+ </div>+ </div>+ </div>+ </div>+ <Modal+ onClose={() => setShowMoreInfoModal(false)}+ onSubmit={() => setShowMoreInfoModal(false)}+ submitText={t('common.gotIt')}+ title='API_URL is not configured'+ message={+ <div className='text-left'>+ <p className='mb-3'>+ You are running Swetrix Community Edition without API_URL set. The frontend cannot reach the API.+ </p>+ <p className='mb-3'>+ Set the API_URL environment variable to your API instance URL. In self-hosting there are two containers:+ </p>+ <ul className='mb-3 list-disc pl-6'>+ <li>swetrix/swetrix-fe β the frontend UI</li>+ <li>swetrix/swetrix-api β the API (auth, data ingest)</li>+ </ul>+ <p className='mb-2 font-medium'>Examples</p>+ <ul className='mb-3 list-disc pl-6'>+ <li>+ Local default: <code>API_URL=http://localhost:8080</code>+ </li>+ <li>+ With subdomains: <code>API_URL=https://swetrix-api.mydomain.com</code>+ </li>+ </ul>+ <p>Please configure it and restart the containers.</p>+ </div>+ }+ type='warning'+ isOpened={showMoreInfoModal}+ />+ </>+ )+}++export default memo(SelfhostedApiUrlBanner)diff --git a/web/app/lib/constants/index.ts b/web/app/lib/constants/index.tsindex 4e4ab6671..48a4809e9 100644--- a/web/app/lib/constants/index.ts+++ b/web/app/lib/constants/index.ts@@ -391,7 +391,7 @@ export const isSelfhosted = Boolean(isBrowser ? window.REMIX_ENV?.SELFHOSTED : pexport const isDisableMarketingPages =(isBrowser ? window.REMIX_ENV?.DISABLE_MARKETING_PAGES : process.env.DISABLE_MARKETING_PAGES) === 'true'-const apiUrlUnprocessed = isSelfhosted || !isStaging ? PRODUCTION_API_URL : STAGING_API_URL+export const apiUrlUnprocessed = isSelfhosted || !isStaging ? PRODUCTION_API_URL : STAGING_API_URLconst cdnUrlUnprocessed = isBrowser ? window.REMIX_ENV?.CDN_URL : process.env.CDN_URLexport const API_URL = _endsWith(apiUrlUnprocessed, '/') ? apiUrlUnprocessed : `${apiUrlUnprocessed}/`diff --git a/web/app/root.tsx b/web/app/root.tsxindex f3fcd2057..3499a0810 100644--- a/web/app/root.tsx+++ b/web/app/root.tsx@@ -22,6 +22,7 @@ import { useChangeLanguage } from 'remix-i18next/react'import { ExternalScripts } from 'remix-utils/external-scripts'import { LocaleLinks } from '~/components/LocaleLinks'+import SelfhostedApiUrlBanner from '~/components/SelfhostedApiUrlBanner'import { SEO } from '~/components/SEO'import { CONTACT_EMAIL, LS_THEME_SETTING, isSelfhosted, I18N_CACHE_BREAKER } from '~/lib/constants'import FlatpickerCss from '~/styles/Flatpicker.css?url'@@ -214,6 +215,7 @@ const Body = () => {return (<body className={cx(theme, { 'bg-gray-50': theme === 'light', 'bg-slate-900': theme === 'dark' })}>+ <SelfhostedApiUrlBanner /><AuthProvider initialIsAuthenticated={isAuthed}><AppWrapper /></AuthProvider>