From c7907f98984530ad013b1f9ebb7043c923f3eaa8 Mon Sep 17 00:00:00 2001 From: zhanghan2021 Date: Thu, 14 Dec 2023 15:33:19 +0800 Subject: [PATCH] Add front-end routing binding --- atune/server/config.yml.templete | 2 +- atune/server/router/router.go | 19 +++++++++++++++++++ atune/web/index.html | 3 ++- atune/web/public/favicon.ico | Bin 0 -> 4286 bytes atune/web/src/router/index.ts | 8 ++------ atune/web/vite.config.ts | 20 ++------------------ 6 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 atune/web/public/favicon.ico diff --git a/atune/server/config.yml.templete b/atune/server/config.yml.templete index 79a1592f..2846aae6 100644 --- a/atune/server/config.yml.templete +++ b/atune/server/config.yml.templete @@ -1,5 +1,5 @@ plugin_atune: - url: "http://localhost:8099/plugin/atune" + url: "http://localhost:8099" plugin_type: "iframe" # iframe micro-app http_server: addr: "localhost:8099" diff --git a/atune/server/router/router.go b/atune/server/router/router.go index c8b61334..c85d9562 100644 --- a/atune/server/router/router.go +++ b/atune/server/router/router.go @@ -1,6 +1,9 @@ package router import ( + "net/http" + "strings" + "gitee.com/openeuler/PilotGo/sdk/logger" "github.com/gin-gonic/gin" "openeuler.org/PilotGo/atune-plugin/config" @@ -29,6 +32,7 @@ func setupRouter() *gin.Engine { router.Use(gin.Recovery()) registerAPIs(router) + StaticRouter(router) return router } @@ -59,3 +63,18 @@ func registerAPIs(router *gin.Engine) { restune.GET("result_search", controller.SearchResult) } } + +func StaticRouter(router *gin.Engine) { + router.Static("/plugin/atune/static", "../web/dist/static") + router.StaticFile("/plugin/atune", "../web/dist/index.html") + + // 解决页面刷新404的问题 + router.NoRoute(func(c *gin.Context) { + logger.Error("process noroute: %s", c.Request.URL) + if !strings.HasPrefix(c.Request.RequestURI, "/plugin/atune/*path") { + c.File("../web/dist/index.html") + return + } + c.Status(http.StatusNotFound) + }) +} diff --git a/atune/web/index.html b/atune/web/index.html index 5d040697..338418c7 100644 --- a/atune/web/index.html +++ b/atune/web/index.html @@ -2,7 +2,8 @@ - + + 智能调优 diff --git a/atune/web/public/favicon.ico b/atune/web/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..df36fcfb72584e00488330b560ebcf34a41c64c2 GIT binary patch literal 4286 zcmds*O-Phc6o&64GDVCEQHxsW(p4>LW*W<827=Unuo8sGpRux(DN@jWP-e29Wl%wj zY84_aq9}^Am9-cWTD5GGEo#+5Fi2wX_P*bo+xO!)p*7B;iKlbFd(U~_d(U?#hLj56 zPhFkj-|A6~Qk#@g^#D^U0XT1cu=c-vu1+SElX9NR;kzAUV(q0|dl0|%h|dI$%VICy zJnu2^L*Te9JrJMGh%-P79CL0}dq92RGU6gI{v2~|)p}sG5x0U*z<8U;Ij*hB9z?ei z@g6Xq-pDoPl=MANPiR7%172VA%r)kevtV-_5H*QJKFmd;8yA$98zCxBZYXTNZ#QFk2(TX0;Y2dt&WitL#$96|gJY=3xX zpCoi|YNzgO3R`f@IiEeSmKrPSf#h#Qd<$%Ej^RIeeYfsxhPMOG`S`Pz8q``=511zm zAm)MX5AV^5xIWPyEu7u>qYs?pn$I4nL9J!=K=SGlKLXpE<5x+2cDTXq?brj?n6sp= zphe9;_JHf40^9~}9i08r{XM$7HB!`{Ys~TK0kx<}ZQng`UPvH*11|q7&l9?@FQz;8 zx!=3<4seY*%=OlbCbcae?5^V_}*K>Uo6ZWV8mTyE^B=DKy7-sdLYkR5Z?paTgK-zyIkKjIcpyO z{+uIt&YSa_$QnN_@t~L014dyK(fOOo+W*MIxbA6Ndgr=Y!f#Tokqv}n<7-9qfHkc3 z=>a|HWqcX8fzQCT=dqVbogRq!-S>H%yA{1w#2Pn;=e>JiEj7Hl;zdt-2f+j2%DeVD zsW0Ab)ZK@0cIW%W7z}H{&~yGhn~D;aiP4=;m-HCo`BEI+Kd6 z={Xwx{TKxD#iCLfl2vQGDitKtN>z|-AdCN|$jTFDg0m3O`WLD4_s#$S literal 0 HcmV?d00001 diff --git a/atune/web/src/router/index.ts b/atune/web/src/router/index.ts index 1595bdf8..06d6afc2 100644 --- a/atune/web/src/router/index.ts +++ b/atune/web/src/router/index.ts @@ -1,13 +1,9 @@ -import { createRouter, createWebHashHistory } from 'vue-router'; +import { createRouter, createWebHistory } from 'vue-router'; import type { RouteRecordRaw } from 'vue-router'; import Home from '@/views/Home.vue'; import Result from '@/views/ResultInfo.vue'; const routes: Array = [ - { - path: '/', - redirect: '/plugin/atune', //使用redirect重定向,默认系统显示的第一页 - }, { path: '/plugin/atune', component: Home, @@ -21,7 +17,7 @@ const routes: Array = [ ]; const router = createRouter({ - history: createWebHashHistory(), + history: createWebHistory('/'), routes, }); diff --git a/atune/web/vite.config.ts b/atune/web/vite.config.ts index ac5d1d57..75a32402 100644 --- a/atune/web/vite.config.ts +++ b/atune/web/vite.config.ts @@ -4,7 +4,7 @@ import path from 'path'; // https://vitejs.dev/config/ export default defineConfig({ - base: './', + base: '/plugin/atune/', plugins: [vue()], resolve: { alias: { @@ -16,10 +16,9 @@ export default defineConfig({ https: false, cors: true, proxy: { - '/plugin': { + '/': { target: 'http://localhost:8099', changeOrigin: true, - rewrite: (path) => path.replace(/^\//, ''), }, }, }, @@ -28,20 +27,5 @@ export default defineConfig({ assetsDir: 'static/', //指定静态资源存放路径 sourcemap: false, //是否构建source map 文件 chunkSizeWarningLimit: 1500, //chunk 大小警告的限制,默认500KB - rollupOptions: { - output: { - // 最小化拆分包 - manualChunks(id) { - if (id.includes('node_modules')) { - return id - .toString() - .split('node_modules/')[1] - .split('/')[0] - .toString(); - } - }, - chunkFileNames: 'js/[name].[hash].js', // 用于命名代码拆分时创建的共享块的输出命名,[name]表示文件名,[hash]表示该文件内容hash值 - }, - }, }, }); -- Gitee