Procházet zdrojové kódy

Add support for custom base URL - resolve #114

Bubka před 2 roky
rodič
revize
8f6bf85fa8

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

@@ -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',

+ 1 - 0
config/2fauth.php

@@ -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', ''),
     ],
 
     /*

+ 7 - 0
public/.htaccess

@@ -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 - 0
resources/js/api.js

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

+ 1 - 0
resources/js/routes.js

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

+ 1 - 1
resources/js/views/auth/Login.vue

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

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

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