Skip to content

📈 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!

stripped non-required parts of Swetrix for selfhosted edition

Blue Mouse9a463ab4b93a
diff --git a/.env.example b/.env.example
index 4b9e403fb..a6a89bb93 100644
--- a/.env.example
+++ b/.env.example
@@ -1,3 +1,4 @@
REACT_APP_API_URL=https://example.com/api/
CHOKIDAR_USEPOLLING=true
GENERATE_SOURCEMAP=false
+REACT_APP_SELFHOSTED=true
diff --git a/src/App.js b/src/App.js
index c7b948095..549d45008 100644
--- a/src/App.js
+++ b/src/App.js
@@ -14,6 +14,7 @@ import Footer from 'components/Footer'
import Loader from 'ui/Loader'
import ScrollToTop from 'hoc/ScrollToTop'
+import Selfhosted from 'hoc/Selfhosted'
import { getAccessToken } from 'utils/accessToken'
import { authMe } from './api'
import { authActions } from 'redux/actions/auth'
@@ -109,29 +110,31 @@ const App = () => {
<>
<Header authenticated={authenticated} />
<ScrollToTop>
- <Suspense fallback={<Fallback isMinimalFooter={isMinimalFooter} />}>
- <Switch>
- <Route path={routes.main} component={MainPage} exact />
- <Route path={routes.signin} component={SignIn} exact />
- <Route path={routes.signup} component={SignUp} exact />
- <Route path={routes.dashboard} component={Dashboard} exact />
- <Route path={routes.user_settings} component={UserSettings} exact />
- <Route path={routes.verify} component={VerifyEmail} exact />
- <Route path={routes.change_email} component={VerifyEmail} exact />
- <Route path={routes.reset_password} component={ForgotPassword} exact />
- <Route path={routes.new_password_form} component={CreateNewPassword} exact />
- <Route path={routes.new_project} component={ProjectSettings} exact />
- <Route path={routes.project_settings} component={ProjectSettings} exact />
- <Route path={routes.project} component={ViewProject} exact />
- <Route path={routes.billing} component={Billing} exact />
- <Route path={routes.docs} component={Docs} exact />
- <Route path={routes.contact} component={Contact} exact />
- <Route path={routes.features} component={Features} exact />
- <Route path={routes.privacy} component={Privacy} exact />
- <Route path={routes.terms} component={Terms} exact />
- <Redirect to={routes.main} />
- </Switch>
- </Suspense>
+ <Selfhosted>
+ <Suspense fallback={<Fallback isMinimalFooter={isMinimalFooter} />}>
+ <Switch>
+ <Route path={routes.main} component={MainPage} exact />
+ <Route path={routes.signin} component={SignIn} exact />
+ <Route path={routes.signup} component={SignUp} exact />
+ <Route path={routes.dashboard} component={Dashboard} exact />
+ <Route path={routes.user_settings} component={UserSettings} exact />
+ <Route path={routes.verify} component={VerifyEmail} exact />
+ <Route path={routes.change_email} component={VerifyEmail} exact />
+ <Route path={routes.reset_password} component={ForgotPassword} exact />
+ <Route path={routes.new_password_form} component={CreateNewPassword} exact />
+ <Route path={routes.new_project} component={ProjectSettings} exact />
+ <Route path={routes.project_settings} component={ProjectSettings} exact />
+ <Route path={routes.project} component={ViewProject} exact />
+ <Route path={routes.billing} component={Billing} exact />
+ <Route path={routes.docs} component={Docs} exact />
+ <Route path={routes.contact} component={Contact} exact />
+ <Route path={routes.features} component={Features} exact />
+ <Route path={routes.privacy} component={Privacy} exact />
+ <Route path={routes.terms} component={Terms} exact />
+ <Redirect to={routes.main} />
+ </Switch>
+ </Suspense>
+ </Selfhosted>
</ScrollToTop>
<Footer minimal={isMinimalFooter} authenticated={authenticated} />
</>
diff --git a/src/components/Footer/index.jsx b/src/components/Footer/index.jsx
index 754d48be9..38faa9d3c 100644
--- a/src/components/Footer/index.jsx
+++ b/src/components/Footer/index.jsx
@@ -6,6 +6,7 @@ import _map from 'lodash/map'
import Flag from 'react-flagkit'
import PropTypes from 'prop-types'
+import { isSelfhosted } from 'redux/constants'
import routes from 'routes'
const STATUSPAGE_URL = 'https://stats.uptimerobot.com/33rvmiXXEz'
@@ -70,11 +71,13 @@ const Footer = ({ minimal, authenticated }) => {
{t('common.docs')}
</Link>
</div>
- <div className='px-5 py-2'>
- <a href={STATUSPAGE_URL} className='text-base text-gray-300 hover:text-white' target='_blank' rel='noopener noreferrer'>
- {t('footer.status')}
- </a>
- </div>
+ {!isSelfhosted && (
+ <div className='px-5 py-2'>
+ <a href={STATUSPAGE_URL} className='text-base text-gray-300 hover:text-white' target='_blank' rel='noopener noreferrer'>
+ {t('footer.status')}
+ </a>
+ </div>
+ )}
</nav>
</div>
</footer>
diff --git a/src/components/Header/index.jsx b/src/components/Header/index.jsx
index 929d3c7ae..940225079 100644
--- a/src/components/Header/index.jsx
+++ b/src/components/Header/index.jsx
@@ -11,7 +11,7 @@ import { MenuIcon, XIcon } from '@heroicons/react/outline'
import routes from 'routes'
import { authActions } from 'redux/actions/auth'
import {
- whitelist, languages, languageFlag,
+ whitelist, languages, languageFlag, isSelfhosted,
} from 'redux/constants'
import Dropdown from 'ui/Dropdown'
@@ -41,19 +41,21 @@ const Header = ({ authenticated }) => {
<NavLink to={routes.features} className='text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-3 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700' key='Features'>
{t('common.features')}
</NavLink>
- {authenticated ? (
- <NavLink to={routes.billing} className='text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-3 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700' key='Billing'>
- {t('common.billing')}
- </NavLink>
- ) : (
- <>
- <HashLink to={`${routes.main}#pricing`} className='text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-3 hover:bg-indigo-500 rounded-md' key='Pricing'>
- {t('common.pricing')}
- </HashLink>
- <HashLink to={`${routes.main}#faqs`} className='text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-3 hover:bg-indigo-500 rounded-md' key='FAQs'>
- {t('common.faqs')}
- </HashLink>
- </>
+ {!isSelfhosted && (
+ authenticated ? (
+ <NavLink to={routes.billing} className='text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-3 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700' key='Billing'>
+ {t('common.billing')}
+ </NavLink>
+ ) : (
+ <>
+ <HashLink to={`${routes.main}#pricing`} className='text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-3 hover:bg-indigo-500 rounded-md' key='Pricing'>
+ {t('common.pricing')}
+ </HashLink>
+ <HashLink to={`${routes.main}#faqs`} className='text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-3 hover:bg-indigo-500 rounded-md' key='FAQs'>
+ {t('common.faqs')}
+ </HashLink>
+ </>
+ )
)}
<NavLink to={routes.docs} className='text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-3 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700' key='Docs'>
{t('common.docs')}
@@ -81,9 +83,11 @@ const Header = ({ authenticated }) => {
/>
{authenticated ? (
<>
- <NavLink to={routes.user_settings} className='text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-3 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700'>
- {t('common.you')}
- </NavLink>
+ {!isSelfhosted && (
+ <NavLink to={routes.user_settings} className='text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-3 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700'>
+ {t('common.you')}
+ </NavLink>
+ )}
<Link to={routes.dashboard} className='inline-block select-none bg-white py-2 px-4 border border-transparent rounded-md text-base font-medium text-indigo-600 hover:bg-indigo-50'>
{t('common.dashboard')}
</Link>
@@ -96,9 +100,11 @@ const Header = ({ authenticated }) => {
<Link to={routes.signin} className='inline-block select-none bg-indigo-500 mt-1 sm:mt-0 py-2 px-3 md:px-4 border border-transparent rounded-md text-base font-medium text-white hover:bg-opacity-75'>
{t('auth.common.signin')}
</Link>
- <Link to={routes.signup} className='inline-block select-none bg-white py-2 px-3 md:px-4 border border-transparent rounded-md text-base font-medium text-indigo-600 hover:bg-indigo-50'>
- {t('common.getStarted')}
- </Link>
+ {!isSelfhosted && (
+ <Link to={routes.signup} className='inline-block select-none bg-white py-2 px-3 md:px-4 border border-transparent rounded-md text-base font-medium text-indigo-600 hover:bg-indigo-50'>
+ {t('common.getStarted')}
+ </Link>
+ )}
</>
)}
</div>
diff --git a/src/hoc/Selfhosted.jsx b/src/hoc/Selfhosted.jsx
new file mode 100644
index 000000000..444080921
--- /dev/null
+++ b/src/hoc/Selfhosted.jsx
@@ -0,0 +1,35 @@
+import React, { useEffect } from 'react'
+import { useHistory } from 'react-router-dom'
+import _includes from 'lodash/includes'
+
+import { isSelfhosted } from 'redux/constants'
+import routes from 'routes'
+
+const selfHostedBlacklist = [
+ routes.signup, routes.reset_password, routes.new_password_form, routes.main, routes.user_settings, routes.verify, routes.change_email,
+]
+
+const DEFAULT_PAGE = routes.signin
+
+const Selfhosted = ({ children }) => {
+ const history = useHistory()
+
+ useEffect(() => {
+ if (isSelfhosted) {
+ if (_includes(selfHostedBlacklist, window.location.pathname)) {
+ history.push(DEFAULT_PAGE)
+ }
+
+ const unlisten = history.listen(({ pathname }) => {
+ if (_includes(selfHostedBlacklist, pathname)) {
+ history.push(DEFAULT_PAGE)
+ }
+ })
+ return unlisten
+ }
+ }, [history])
+
+ return <>{children}</>
+}
+
+export default Selfhosted
diff --git a/src/pages/Auth/Signin/Signin.jsx b/src/pages/Auth/Signin/Signin.jsx
index 372181c7c..73198ab10 100644
--- a/src/pages/Auth/Signin/Signin.jsx
+++ b/src/pages/Auth/Signin/Signin.jsx
@@ -12,6 +12,7 @@ import Checkbox from 'ui/Checkbox'
import {
isValidEmail, isValidPassword, MIN_PASSWORD_CHARS,
} from 'utils/validator'
+import { isSelfhosted } from 'redux/constants'
const Signin = ({ login }) => {
const { t } = useTranslation('common')
@@ -115,13 +116,17 @@ const Signin = ({ login }) => {
/>
<div className='flex justify-between mt-3'>
<div className='pt-1'>
- <Link to={routes.reset_password} className='underline text-blue-600 hover:text-indigo-800'>
- {t('auth.signin.forgot')}
- </Link>
- <span>&nbsp;|&nbsp;</span>
- <Link to={routes.signup} className='underline text-blue-600 hover:text-indigo-800'>
- {t('auth.common.signupInstead')}
- </Link>
+ {!isSelfhosted && (
+ <>
+ <Link to={routes.reset_password} className='underline text-blue-600 hover:text-indigo-800'>
+ {t('auth.signin.forgot')}
+ </Link>
+ <span>&nbsp;|&nbsp;</span>
+ <Link to={routes.signup} className='underline text-blue-600 hover:text-indigo-800'>
+ {t('auth.common.signupInstead')}
+ </Link>
+ </>
+ )}
</div>
<Button type='submit' loading={isLoading} primary large>
{t('auth.signin.button')}
diff --git a/src/redux/constants/index.js b/src/redux/constants/index.js
index e3d500ced..c41a38638 100644
--- a/src/redux/constants/index.js
+++ b/src/redux/constants/index.js
@@ -45,6 +45,8 @@ export const TOKEN = 'access_token'
export const TITLE_SUFFIX = '| Swetrix'
+export const isSelfhosted = process.env.REACT_APP_SELFHOSTED
+
// Functions
export const getProjectCacheKey = (period, timeBucket) => `${period}${timeBucket}`