Add support for custom base URL - resolve #114

This commit is contained in:
Bubka 2023-01-20 17:36:15 +01:00
parent 17137b9885
commit 8f6bf85fa8
7 changed files with 20 additions and 6 deletions

View File

@ -22,6 +22,7 @@ class SinglePageController extends Controller
'appConfig' => collect([
'proxyAuth' => config('auth.defaults.guard') === 'reverse-proxy-guard' ? true : false,
'proxyLogoutUrl' => config('2fauth.config.proxyLogoutUrl') ? config('2fauth.config.proxyLogoutUrl') : false,
'subdirectory' => '/' . config('2fauth.config.appSubdirectory') . '/',
])->toJson(),
'lang' => App::currentLocale(),
'isDemoApp' => config('2fauth.config.isDemoApp') ? 'true' : 'false',

View File

@ -26,6 +26,7 @@ return [
'isTestingApp' => env('IS_TESTING_APP', false),
'trustedProxies' => env('TRUSTED_PROXIES', null),
'proxyLogoutUrl' => env('PROXY_LOGOUT_URL', null),
'appSubdirectory' => env('APP_SUBDIR', ''),
],
/*

View File

@ -5,6 +5,13 @@
RewriteEngine On
# Uncomment and set the RewriteBase path to the desired subdirectory if you want to
# serve 2FAuth from a domain subdirectory like https://mydomain/2fauth/
#
# WARNING: the subdirectory value must match the one set in your .env file
# Do not forget leading and trailing slashes.
#RewriteBase /subdir/
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

4
resources/js/api.js vendored
View File

@ -8,6 +8,10 @@ Vue.use(VueAxios, axios)
Vue.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
Vue.axios.defaults.headers.common['Content-Type'] = 'application/json'
if (window.appConfig.APP_SUBDIRECTORY) {
Vue.axios.defaults.baseURL = window.appConfig.subdirectory;
}
Vue.axios.interceptors.response.use(response => response, error => {
// Return the error when we need to handle it at component level

View File

@ -31,6 +31,7 @@ import About from './views/About'
const router = new Router({
mode: 'history',
base: window.appConfig.subdirectory ? window.appConfig.subdirectory : '/',
routes: [
{ path: '/start', name: 'start', component: Start, meta: { requiresAuth: true }, props: true },
{ path: '/capture', name: 'capture', component: Capture, meta: { requiresAuth: true }, props: true },

View File

@ -149,7 +149,7 @@
beforeRouteEnter (to, from, next) {
if (to.params.forceRefresh && from.name !== null) {
window.location.href = to.path;
window.location.href = "." + to.path;
return;
}

View File

@ -16,8 +16,8 @@
<link rel="apple-touch-icon" href="{{ asset('favicon_lg.png') }}" />
<link rel="apple-touch-icon-precomposed" href="{{ asset('favicon_lg.png') }}" />
<link rel="manifest" href="/manifest.json">
<link href=" {{ mix('css/app.css') }}" rel="stylesheet">
<link href=".{{ mix('css/app.css') }}" rel="stylesheet">
</head>
<body class="has-text-lighter">
<div id="app">
@ -31,8 +31,8 @@
var isTestingApp = {!! $isTestingApp !!};
var appLocales = {!! $locales !!};
</script>
<script src="{{ mix('js/manifest.js') }}"></script>
<script src="{{ mix('js/vendor.js') }}"></script>
<script src="{{ mix('js/app.js') }}"></script>
<script src=".{{ mix('js/manifest.js') }}"></script>
<script src=".{{ mix('js/vendor.js') }}"></script>
<script src=".{{ mix('js/app.js') }}"></script>
</body>
</html>