mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
[DEV] Fix webpack for development workflow (#1163)
This commit is contained in:
parent
ccc5ce8b42
commit
160e98f275
|
@ -17,10 +17,10 @@ import NotificationsContext from './hooks/NotificationsContext';
|
||||||
import { Notification } from './models/Notifications';
|
import { Notification } from './models/Notifications';
|
||||||
import NotificationBar from './components/NotificationBar';
|
import NotificationBar from './components/NotificationBar';
|
||||||
import SignOut from './views/LoginPortal/SignOut/SignOut';
|
import SignOut from './views/LoginPortal/SignOut/SignOut';
|
||||||
import { useRememberMe, useResetPassword } from './hooks/Configuration';
|
import { getRememberMe, getResetPassword } from './utils/Configuration';
|
||||||
import '@fortawesome/fontawesome-svg-core/styles.css'
|
import '@fortawesome/fontawesome-svg-core/styles.css'
|
||||||
import { config as faConfig } from '@fortawesome/fontawesome-svg-core';
|
import { config as faConfig } from '@fortawesome/fontawesome-svg-core';
|
||||||
import { useBasePath } from './hooks/BasePath';
|
import { getBasePath } from './utils/BasePath';
|
||||||
|
|
||||||
faConfig.autoAddCss = false;
|
faConfig.autoAddCss = false;
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ const App: React.FC = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NotificationsContext.Provider value={{ notification, setNotification }} >
|
<NotificationsContext.Provider value={{ notification, setNotification }} >
|
||||||
<Router basename={useBasePath()}>
|
<Router basename={getBasePath()}>
|
||||||
<NotificationBar onClose={() => setNotification(null)} />
|
<NotificationBar onClose={() => setNotification(null)} />
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path={ResetPasswordStep1Route} exact>
|
<Route path={ResetPasswordStep1Route} exact>
|
||||||
|
@ -49,8 +49,8 @@ const App: React.FC = () => {
|
||||||
</Route>
|
</Route>
|
||||||
<Route path={FirstFactorRoute}>
|
<Route path={FirstFactorRoute}>
|
||||||
<LoginPortal
|
<LoginPortal
|
||||||
rememberMe={useRememberMe()}
|
rememberMe={getRememberMe()}
|
||||||
resetPassword={useResetPassword()} />
|
resetPassword={getResetPassword()} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/">
|
<Route path="/">
|
||||||
<Redirect to={FirstFactorRoute} />
|
<Redirect to={FirstFactorRoute} />
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
import { useBasePath } from "./BasePath";
|
|
||||||
|
|
||||||
__webpack_public_path__ = "/"
|
|
||||||
|
|
||||||
if (useBasePath() !== "") {
|
|
||||||
__webpack_public_path__ = useBasePath() + "/"
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
import { useEmbeddedVariable } from "./Configuration";
|
|
||||||
|
|
||||||
export function useBasePath() {
|
|
||||||
return useEmbeddedVariable("basepath");
|
|
||||||
}
|
|
|
@ -1,23 +1,6 @@
|
||||||
import { useRemoteCall } from "./RemoteCall";
|
import { useRemoteCall } from "./RemoteCall";
|
||||||
import { getConfiguration } from "../services/Configuration";
|
import { getConfiguration } from "../services/Configuration";
|
||||||
|
|
||||||
export function useEmbeddedVariable(variableName: string) {
|
|
||||||
const value = document.body.getAttribute(`data-${variableName}`);
|
|
||||||
if (value === null) {
|
|
||||||
throw new Error(`No ${variableName} embedded variable detected`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useRememberMe() {
|
|
||||||
return useEmbeddedVariable("rememberme") === "true";
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useResetPassword() {
|
|
||||||
return useEmbeddedVariable("disable-resetpassword") === "true";
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useConfiguration() {
|
export function useConfiguration() {
|
||||||
return useRemoteCall(getConfiguration, []);
|
return useRemoteCall(getConfiguration, []);
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
import './hooks/AssetPath';
|
import './utils/AssetPath';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { AxiosResponse } from "axios";
|
import { AxiosResponse } from "axios";
|
||||||
import { useBasePath } from "../hooks/BasePath";
|
import { getBasePath } from "../utils/BasePath";
|
||||||
|
|
||||||
const basePath = useBasePath();
|
const basePath = getBasePath();
|
||||||
|
|
||||||
export const FirstFactorPath = basePath + "/api/firstfactor";
|
export const FirstFactorPath = basePath + "/api/firstfactor";
|
||||||
export const InitiateTOTPRegistrationPath = basePath + "/api/secondfactor/totp/identity/start";
|
export const InitiateTOTPRegistrationPath = basePath + "/api/secondfactor/totp/identity/start";
|
||||||
|
|
7
web/src/utils/AssetPath.ts
Normal file
7
web/src/utils/AssetPath.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { getBasePath } from "./BasePath";
|
||||||
|
|
||||||
|
__webpack_public_path__ = "/"
|
||||||
|
|
||||||
|
if (getBasePath() !== "") {
|
||||||
|
__webpack_public_path__ = getBasePath() + "/"
|
||||||
|
}
|
5
web/src/utils/BasePath.ts
Normal file
5
web/src/utils/BasePath.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { getEmbeddedVariable } from "./Configuration";
|
||||||
|
|
||||||
|
export function getBasePath() {
|
||||||
|
return getEmbeddedVariable("basepath");
|
||||||
|
}
|
16
web/src/utils/Configuration.ts
Normal file
16
web/src/utils/Configuration.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
export function getEmbeddedVariable(variableName: string) {
|
||||||
|
const value = document.body.getAttribute(`data-${variableName}`);
|
||||||
|
if (value === null) {
|
||||||
|
throw new Error(`No ${variableName} embedded variable detected`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRememberMe() {
|
||||||
|
return getEmbeddedVariable("rememberme") === "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getResetPassword() {
|
||||||
|
return getEmbeddedVariable("disable-resetpassword") === "true";
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user