Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Add force SSL check.
Mike Cao4cafa68e23d4
diff --git a/hooks/useForceSSL.js b/hooks/useForceSSL.jsnew file mode 100644index 000000000..b9d95e190--- /dev/null+++ b/hooks/useForceSSL.js@@ -0,0 +1,14 @@+import { useEffect } from 'react';+import { useRouter } from 'next/router';++export default function useForceSSL(enabled) {+ const router = useRouter();++ useEffect(() => {+ if (enabled && typeof window !== 'undefined' && /^http:\/\//.test(location.href)) {+ router.push(location.href.replace(/^http:\/\//, 'https://'));+ }+ }, [enabled]);++ return null;+}diff --git a/next.config.js b/next.config.jsindex c1e31d7b9..9d7d8e993 100644--- a/next.config.js+++ b/next.config.js@@ -4,9 +4,7 @@ const pkg = require('./package.json');module.exports = {env: {VERSION: pkg.version,- },- serverRuntimeConfig: {- PROJECT_ROOT: __dirname,+ FORCE_SSL: !!process.env.FORCE_SSL,},webpack(config) {config.module.rules.push({diff --git a/package.json b/package.jsonindex c5553e412..f5fe6909e 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "umami",- "version": "0.75.0",+ "version": "0.76.0","description": "A simple, fast, website analytics alternative to Google Analytics. ","author": "Mike Cao <[email protected]>","license": "MIT",diff --git a/pages/_app.js b/pages/_app.jsindex 9aad4339d..2849d2f01 100644--- a/pages/_app.js+++ b/pages/_app.js@@ -3,6 +3,7 @@ import { IntlProvider } from 'react-intl';import { Provider } from 'react-redux';import { useStore } from 'redux/store';import useLocale from 'hooks/useLocale';+import useForceSSL from 'hooks/useForceSSL';import { messages } from 'lib/lang';import 'styles/variables.css';import 'styles/bootstrap-grid.css';@@ -21,6 +22,7 @@ const Intl = ({ children }) => {};export default function App({ Component, pageProps }) {+ useForceSSL(process.env.FORCE_SSL);const store = useStore();return (