浏览代码

Fix custom base URL support

Bubka 2 年之前
父节点
当前提交
dcc6579365
共有 5 个文件被更改,包括 21 次插入7 次删除
  1. 11 0
      .env.example
  2. 4 1
      app/Http/Controllers/SinglePageController.php
  3. 1 1
      config/2fauth.php
  4. 1 1
      resources/js/api.js
  5. 4 4
      resources/views/landing.blade.php

+ 11 - 0
.env.example

@@ -32,6 +32,17 @@ APP_KEY=SomeRandomStringOf32CharsExactly
 APP_URL=http://localhost
 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.
 # 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.
 # 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());
         event(new ScanForNewReleaseCalled());
 
 
+        $subdir = config('2fauth.config.appSubdirectory') ? '/' . config('2fauth.config.appSubdirectory') : '';
+
         return view('landing')->with([
         return view('landing')->with([
             'appSettings' => Settings::all()->toJson(),
             'appSettings' => Settings::all()->toJson(),
             'appConfig'   => collect([
             'appConfig'   => collect([
                 'proxyAuth'      => config('auth.defaults.guard') === 'reverse-proxy-guard' ? true : false,
                 'proxyAuth'      => config('auth.defaults.guard') === 'reverse-proxy-guard' ? true : false,
                 'proxyLogoutUrl' => config('2fauth.config.proxyLogoutUrl') ? config('2fauth.config.proxyLogoutUrl') : false,
                 'proxyLogoutUrl' => config('2fauth.config.proxyLogoutUrl') ? config('2fauth.config.proxyLogoutUrl') : false,
-                'subdirectory'    => '/' . config('2fauth.config.appSubdirectory') . '/',
+                'subdirectory'   => $subdir,
             ])->toJson(),
             ])->toJson(),
+            'subdirectory' => $subdir,
             'lang'         => App::currentLocale(),
             'lang'         => App::currentLocale(),
             'isDemoApp'    => config('2fauth.config.isDemoApp') ? 'true' : 'false',
             'isDemoApp'    => config('2fauth.config.isDemoApp') ? 'true' : 'false',
             'isTestingApp' => config('2fauth.config.isTestingApp') ? '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),
         'isTestingApp' => env('IS_TESTING_APP', false),
         'trustedProxies' => env('TRUSTED_PROXIES', null),
         'trustedProxies' => env('TRUSTED_PROXIES', null),
         'proxyLogoutUrl' => env('PROXY_LOGOUT_URL', 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['X-Requested-With'] = 'XMLHttpRequest';
 Vue.axios.defaults.headers.common['Content-Type'] = 'application/json'
 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;
     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="apple-touch-icon-precomposed" href="{{ asset('favicon_lg.png') }}" />
     <link rel="manifest" href="/manifest.json">
     <link rel="manifest" href="/manifest.json">
 
 
-    <link href=".{{ mix('css/app.css') }}" rel="stylesheet">
+    <link href="{!! $subdirectory !!}{{ mix('css/app.css') }}" rel="stylesheet">
 </head>
 </head>
 <body class="has-text-lighter">
 <body class="has-text-lighter">
     <div id="app">
     <div id="app">
@@ -31,8 +31,8 @@
         var isTestingApp = {!! $isTestingApp !!};
         var isTestingApp = {!! $isTestingApp !!};
         var appLocales = {!! $locales !!};
         var appLocales = {!! $locales !!};
     </script>
     </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>
 </body>
 </html>
 </html>