Parcourir la source

Fix custom base URL support

Bubka il y a 2 ans
Parent
commit
dcc6579365

+ 11 - 0
.env.example

@@ -32,6 +32,17 @@ APP_KEY=SomeRandomStringOf32CharsExactly
 APP_URL=http://localhost
 
 
+# The domain subdirectory from which you want to serve 2FAuth.
+# This must reflect the path targeted by APP_URL.
+#
+# For example, if you set APP_URL=https://mydomain.org/2fa to access 2FAuth from the '/2fa/' subdirectory
+# you have to set APP_SUBDIRECTORY=2fa
+#
+# Leave blank if you serve 2FAuth from the domain root.
+
+APP_SUBDIRECTORY=
+
+
 # Turn this to true if you want your app to react like a demo.
 # The Demo mode reset the app content every hours and set a generic demo user.
 

+ 4 - 1
app/Http/Controllers/SinglePageController.php

@@ -17,13 +17,16 @@ class SinglePageController extends Controller
     {
         event(new ScanForNewReleaseCalled());
 
+        $subdir = config('2fauth.config.appSubdirectory') ? '/' . config('2fauth.config.appSubdirectory') : '';
+
         return view('landing')->with([
             'appSettings' => Settings::all()->toJson(),
             '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') . '/',
+                'subdirectory'   => $subdir,
             ])->toJson(),
+            'subdirectory' => $subdir,
             'lang'         => App::currentLocale(),
             'isDemoApp'    => config('2fauth.config.isDemoApp') ? 'true' : 'false',
             'isTestingApp' => config('2fauth.config.isTestingApp') ? 'true' : 'false',

+ 1 - 1
config/2fauth.php

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

+ 1 - 1
resources/js/api.js

@@ -8,7 +8,7 @@ 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) {
+if (window.appConfig.subdirectory) {
     Vue.axios.defaults.baseURL = window.appConfig.subdirectory;
 }
 

+ 4 - 4
resources/views/landing.blade.php

@@ -17,7 +17,7 @@
     <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="{!! $subdirectory !!}{{ 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="{!! $subdirectory !!}{{ mix('js/manifest.js') }}"></script>
+    <script src="{!! $subdirectory !!}{{ mix('js/vendor.js') }}"></script>
+    <script src="{!! $subdirectory !!}{{ mix('js/app.js') }}"></script>
 </body>
 </html>