Skip to content

Commit f8488a1

Browse files
committed
feat: supported sub path deployment #68
1 parent 612d656 commit f8488a1

File tree

12 files changed

+77
-64
lines changed

12 files changed

+77
-64
lines changed

frontend/.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VITE_API_ROOT = /api
1+
VITE_API_ROOT=/api

frontend/.env.production

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VITE_API_ROOT = /api
1+
VITE_API_ROOT=api

frontend/src/lib/helper/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,18 @@ function downloadCsv(header: any, data: any[], fileName: string) {
3131
window.URL.revokeObjectURL(csvContent)
3232
}
3333

34+
const urlJoin = (...args: string[]) =>
35+
args
36+
.join('/')
37+
.replace(/[\/]+/g, '/')
38+
.replace(/^(.+):\//, '$1://')
39+
.replace(/^file:/, 'file:/')
40+
.replace(/\/(\?|&|#[^!])/g, '$1')
41+
.replace(/\?/g, '&')
42+
.replace('&', '?')
43+
3444
export {
3545
bytesToSize,
36-
downloadCsv
46+
downloadCsv,
47+
urlJoin
3748
}

frontend/src/lib/http/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ let instance = axios.create({
1919
headers['Content-Type'] = 'application/json'
2020
}
2121
return JSON.stringify(data)
22-
}],
22+
}]
2323
})
2424

2525

2626
instance.interceptors.request.use(
2727
config => {
2828
if (token) {
29-
(config.headers || {}).Authorization = token.value
29+
(config.headers as any).Authorization = token.value
3030
}
3131
return config
3232
},

frontend/src/lib/websocket/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ReconnectingWebSocket from 'reconnecting-websocket'
22
import {useUserStore} from '@/pinia'
33
import {storeToRefs} from 'pinia'
4+
import {urlJoin} from '@/lib/helper'
45

56

67
function ws(url: string, reconnect: boolean = true): ReconnectingWebSocket | WebSocket {
@@ -9,7 +10,8 @@ function ws(url: string, reconnect: boolean = true): ReconnectingWebSocket | Web
910

1011
const protocol = location.protocol === 'https:' ? 'wss://' : 'ws://'
1112

12-
const _url = protocol + window.location.host + url + '?token=' + btoa(token.value)
13+
const _url = urlJoin(protocol + window.location.host, window.location.pathname,
14+
url, '?token=' + btoa(token.value))
1315

1416
if (reconnect) {
1517
return new ReconnectingWebSocket(_url)

frontend/src/routes/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createRouter, createWebHistory} from 'vue-router'
1+
import {createRouter, createWebHashHistory, createWebHistory} from 'vue-router'
22
import gettext from '../gettext'
33
import {useUserStore} from '@/pinia'
44

@@ -169,7 +169,7 @@ export const routes = [
169169
]
170170

171171
const router = createRouter({
172-
history: createWebHistory(),
172+
history: createWebHashHistory(),
173173
// @ts-ignore
174174
routes: routes
175175
})

frontend/src/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"1.7.2","build_id":67,"total_build":137}
1+
{"version":"1.7.2","build_id":73,"total_build":143}

frontend/src/views/dashboard/DashBoard.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import {onMounted, onUnmounted, reactive, ref} from 'vue'
77
import analytic from '@/api/analytic'
88
import ws from '@/lib/websocket'
99
import {bytesToSize} from '@/lib/helper'
10+
import ReconnectingWebSocket from 'reconnecting-websocket'
1011
1112
const {$gettext} = useGettext()
1213
13-
const websocket = ws('/api/analytic')
14-
websocket.onmessage = wsOnMessage
14+
let websocket: ReconnectingWebSocket | WebSocket
1515
1616
const host = reactive({})
1717
const cpu = ref('0.0')
@@ -61,6 +61,9 @@ onMounted(() => {
6161
disk_io_analytic[0].data = disk_io_analytic[0].data.concat(r.disk_io.writes)
6262
disk_io_analytic[1].data = disk_io_analytic[1].data.concat(r.disk_io.reads)
6363
64+
websocket = ws('api/analytic')
65+
websocket.onmessage = wsOnMessage
66+
6467
})
6568
})
6669

frontend/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"1.7.2","build_id":67,"total_build":137}
1+
{"version":"1.7.2","build_id":73,"total_build":143}

frontend/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import vitePluginBuildId from 'vite-plugin-build-id'
99

1010
// https://vitejs.dev/config/
1111
export default defineConfig({
12+
base: './',
1213
resolve: {
1314
alias: {
1415
'@': fileURLToPath(new URL('./src', import.meta.url))

0 commit comments

Comments
 (0)