Browse Source

Добавки для правильной работы с nginx

Book Pauk 4 năm trước cách đây
mục cha
commit
37e0e1d42f
2 tập tin đã thay đổi với 19 bổ sung10 xóa
  1. 17 9
      client/components/App.vue
  2. 2 1
      client/router.js

+ 17 - 9
client/components/App.vue

@@ -193,18 +193,26 @@ class App extends Vue {
     }
 
     redirectIfNeeded() {
-        if ((this.mode == 'reader' || this.mode == 'omnireader' || this.mode == 'liberama.top') && (!this.isReaderActive)) {
-            //старый url
+        if ((this.mode == 'reader' || this.mode == 'omnireader' || this.mode == 'liberama.top')) {
             const search = window.location.search.substr(1);
-            const s = search.split('url=');
-            const url = s[1] || '';
-            const q = utils.parseQuery(s[0] || '');
-            if (url) {
-                q.url = decodeURIComponent(url);
+            //распознавание параметра p , если присутствует, должен совпадать с rootRoute (необходимо для nginx)
+            const q = utils.parseQuery(search);
+            if (q.p && `/${q.p}` != this.rootRoute) {
+                this.$router.replace('/404');
             }
 
-            window.history.replaceState({}, '', '/');
-            this.$router.replace({ path: '/reader', query: q });
+            //распознавание параметра url вида "?url=<link>" и редирект при необходимости
+            if (!this.isReaderActive) {
+                const s = search.split('url=');
+                const url = s[1] || '';
+                const q = utils.parseQuery(s[0] || '');
+                if (url) {
+                    q.url = decodeURIComponent(url);
+                }
+
+                window.history.replaceState({}, '', '/');
+                this.$router.replace({ path: '/reader', query: q });
+            }
         }
     }
 }

+ 2 - 1
client/router.js

@@ -17,7 +17,7 @@ const Income = () => import('./components/Income/Income.vue');
 const Sources = () => import('./components/Sources/Sources.vue');
 const Settings = () => import('./components/Settings/Settings.vue');
 const Help = () => import('./components/Help/Help.vue');
-//const NotFound404 = () => import('./components/NotFound404/NotFound404.vue');
+const NotFound404 = () => import('./components/NotFound404/NotFound404.vue');
 
 const myRoutes = [
     ['/', null, null, '/cardindex'],
@@ -35,6 +35,7 @@ const myRoutes = [
     ['/sources', Sources],
     ['/settings', Settings],
     ['/help', Help],
+    ['/404', NotFound404],
     ['*', null, null, '/cardindex'],
 ];