Add force SSL check.

This commit is contained in:
Mike Cao 2020-10-03 21:54:21 -07:00
parent fc22f5969c
commit 4cafa68e23
4 changed files with 18 additions and 4 deletions

14
hooks/useForceSSL.js Normal file
View File

@ -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;
}

View File

@ -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({

View File

@ -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 <mike@mikecao.com>",
"license": "MIT",

View File

@ -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 (