feat: 增加 xpack 相关代码 (#3407)

This commit is contained in:
zhengkunwang 2023-12-20 22:44:09 +08:00 committed by GitHub
parent 74dd3ce6c3
commit 326bcb5b3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 103 additions and 86 deletions

9
.gitignore vendored
View File

@ -21,13 +21,6 @@ build/1panel
*.iml *.iml
*.ipr *.ipr
# NetBeans
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test
@ -44,6 +37,8 @@ cmd/server/web/monacoeditorwork
cmd/server/web/index.html cmd/server/web/index.html
frontend/auto-imports.d.ts frontend/auto-imports.d.ts
frontend/components.d.ts frontend/components.d.ts
frontend/src/xpack
backend/xpack
.history/ .history/
dist/ dist/

View File

@ -2,20 +2,23 @@ package router
import ( import (
"fmt" "fmt"
"github.com/gin-contrib/gzip"
"html/template"
"net/http"
"github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/i18n" "github.com/1Panel-dev/1Panel/backend/i18n"
"github.com/1Panel-dev/1Panel/backend/middleware" "github.com/1Panel-dev/1Panel/backend/middleware"
rou "github.com/1Panel-dev/1Panel/backend/router" rou "github.com/1Panel-dev/1Panel/backend/router"
"github.com/1Panel-dev/1Panel/cmd/server/docs" "github.com/1Panel-dev/1Panel/cmd/server/docs"
"github.com/1Panel-dev/1Panel/cmd/server/web" "github.com/1Panel-dev/1Panel/cmd/server/web"
"github.com/gin-contrib/gzip"
ginI18n "github.com/gin-contrib/i18n" ginI18n "github.com/gin-contrib/i18n"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
swaggerfiles "github.com/swaggo/files" swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger" ginSwagger "github.com/swaggo/gin-swagger"
"html/template"
"net/http"
)
var (
Router *gin.Engine
) )
func setWebStatic(rootRouter *gin.RouterGroup) { func setWebStatic(rootRouter *gin.RouterGroup) {
@ -35,7 +38,7 @@ func setWebStatic(rootRouter *gin.RouterGroup) {
} }
func Routers() *gin.Engine { func Routers() *gin.Engine {
Router := gin.Default() Router = gin.Default()
Router.Use(middleware.OperationLog()) Router.Use(middleware.OperationLog())
// Router.Use(middleware.CSRF()) // Router.Use(middleware.CSRF())
// Router.Use(middleware.LoadCsrfToken()) // Router.Use(middleware.LoadCsrfToken())
@ -55,7 +58,6 @@ func Routers() *gin.Engine {
"Localize": ginI18n.GetMessage, "Localize": ginI18n.GetMessage,
}) })
systemRouter := rou.RouterGroupApp
swaggerRouter := Router.Group("1panel") swaggerRouter := Router.Group("1panel")
docs.SwaggerInfo.BasePath = "/api/v1" docs.SwaggerInfo.BasePath = "/api/v1"
swaggerRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) swaggerRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
@ -71,29 +73,8 @@ func Routers() *gin.Engine {
PrivateGroup.Use(middleware.WhiteAllow()) PrivateGroup.Use(middleware.WhiteAllow())
PrivateGroup.Use(middleware.BindDomain()) PrivateGroup.Use(middleware.BindDomain())
PrivateGroup.Use(middleware.GlobalLoading()) PrivateGroup.Use(middleware.GlobalLoading())
{ for _, router := range rou.RouterGroupApp {
systemRouter.InitBaseRouter(PrivateGroup) router.InitRouter(PrivateGroup)
systemRouter.InitDashboardRouter(PrivateGroup)
systemRouter.InitHostRouter(PrivateGroup)
systemRouter.InitContainerRouter(PrivateGroup)
systemRouter.InitTerminalRouter(PrivateGroup)
systemRouter.InitMonitorRouter(PrivateGroup)
systemRouter.InitLogRouter(PrivateGroup)
systemRouter.InitFileRouter(PrivateGroup)
systemRouter.InitCronjobRouter(PrivateGroup)
systemRouter.InitSettingRouter(PrivateGroup)
systemRouter.InitAppRouter(PrivateGroup)
systemRouter.InitWebsiteRouter(PrivateGroup)
systemRouter.InitWebsiteGroupRouter(PrivateGroup)
systemRouter.InitWebsiteDnsAccountRouter(PrivateGroup)
systemRouter.InitDatabaseRouter(PrivateGroup)
systemRouter.InitWebsiteSSLRouter(PrivateGroup)
systemRouter.InitWebsiteAcmeAccountRouter(PrivateGroup)
systemRouter.InitNginxRouter(PrivateGroup)
systemRouter.InitRuntimeRouter(PrivateGroup)
systemRouter.InitProcessRouter(PrivateGroup)
systemRouter.InitToolboxRouter(PrivateGroup)
systemRouter.InitWebsiteCARouter(PrivateGroup)
} }
return Router return Router

27
backend/router/common.go Normal file
View File

@ -0,0 +1,27 @@
package router
func commonGroups() []CommonRouter {
return []CommonRouter{
&BaseRouter{},
&DashboardRouter{},
&HostRouter{},
&ContainerRouter{},
&MonitorRouter{},
&LogRouter{},
&FileRouter{},
&ToolboxRouter{},
&TerminalRouter{},
&CronjobRouter{},
&SettingRouter{},
&AppRouter{},
&WebsiteRouter{},
&WebsiteGroupRouter{},
&WebsiteDnsAccountRouter{},
&WebsiteAcmeAccountRouter{},
&WebsiteSSLRouter{},
&DatabaseRouter{},
&NginxRouter{},
&RuntimeRouter{},
&ProcessRouter{},
}
}

View File

@ -1,27 +1,9 @@
//go:build !xpack
package router package router
type RouterGroup struct { func RouterGroups() []CommonRouter {
BaseRouter return commonGroups()
DashboardRouter
HostRouter
ContainerRouter
MonitorRouter
LogRouter
FileRouter
ToolboxRouter
TerminalRouter
CronjobRouter
SettingRouter
AppRouter
WebsiteRouter
WebsiteGroupRouter
WebsiteDnsAccountRouter
WebsiteAcmeAccountRouter
WebsiteSSLRouter
DatabaseRouter
NginxRouter
RuntimeRouter
ProcessRouter
} }
var RouterGroupApp = new(RouterGroup) var RouterGroupApp = RouterGroups()

View File

@ -0,0 +1,11 @@
//go:build xpack
package router
import "github.com/1Panel-dev/1Panel/backend/xpack/router"
func RouterGroups() []CommonRouter {
return append(commonGroups(), []CommonRouter{&router.WafRouter{}}...)
}
var RouterGroupApp = RouterGroups()

View File

@ -9,7 +9,7 @@ import (
type AppRouter struct { type AppRouter struct {
} }
func (a *AppRouter) InitAppRouter(Router *gin.RouterGroup) { func (a *AppRouter) InitRouter(Router *gin.RouterGroup) {
appRouter := Router.Group("apps") appRouter := Router.Group("apps")
appRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired()) appRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())

View File

@ -7,7 +7,7 @@ import (
type BaseRouter struct{} type BaseRouter struct{}
func (s *BaseRouter) InitBaseRouter(Router *gin.RouterGroup) { func (s *BaseRouter) InitRouter(Router *gin.RouterGroup) {
baseRouter := Router.Group("auth") baseRouter := Router.Group("auth")
baseApi := v1.ApiGroupApp.BaseApi baseApi := v1.ApiGroupApp.BaseApi
{ {

View File

@ -8,7 +8,7 @@ import (
type ContainerRouter struct{} type ContainerRouter struct{}
func (s *ContainerRouter) InitContainerRouter(Router *gin.RouterGroup) { func (s *ContainerRouter) InitRouter(Router *gin.RouterGroup) {
baRouter := Router.Group("containers"). baRouter := Router.Group("containers").
Use(middleware.JwtAuth()). Use(middleware.JwtAuth()).
Use(middleware.SessionAuth()). Use(middleware.SessionAuth()).

View File

@ -9,7 +9,7 @@ import (
type CronjobRouter struct{} type CronjobRouter struct{}
func (s *CronjobRouter) InitCronjobRouter(Router *gin.RouterGroup) { func (s *CronjobRouter) InitRouter(Router *gin.RouterGroup) {
cmdRouter := Router.Group("cronjobs"). cmdRouter := Router.Group("cronjobs").
Use(middleware.JwtAuth()). Use(middleware.JwtAuth()).
Use(middleware.SessionAuth()). Use(middleware.SessionAuth()).

View File

@ -9,7 +9,7 @@ import (
type DashboardRouter struct{} type DashboardRouter struct{}
func (s *CronjobRouter) InitDashboardRouter(Router *gin.RouterGroup) { func (s *DashboardRouter) InitRouter(Router *gin.RouterGroup) {
cmdRouter := Router.Group("dashboard"). cmdRouter := Router.Group("dashboard").
Use(middleware.JwtAuth()). Use(middleware.JwtAuth()).
Use(middleware.SessionAuth()). Use(middleware.SessionAuth()).

View File

@ -9,7 +9,7 @@ import (
type DatabaseRouter struct{} type DatabaseRouter struct{}
func (s *DatabaseRouter) InitDatabaseRouter(Router *gin.RouterGroup) { func (s *DatabaseRouter) InitRouter(Router *gin.RouterGroup) {
cmdRouter := Router.Group("databases"). cmdRouter := Router.Group("databases").
Use(middleware.JwtAuth()). Use(middleware.JwtAuth()).
Use(middleware.SessionAuth()). Use(middleware.SessionAuth()).

View File

@ -9,7 +9,7 @@ import (
type FileRouter struct { type FileRouter struct {
} }
func (f *FileRouter) InitFileRouter(Router *gin.RouterGroup) { func (f *FileRouter) InitRouter(Router *gin.RouterGroup) {
fileRouter := Router.Group("files") fileRouter := Router.Group("files")
fileRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired()) fileRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())
baseApi := v1.ApiGroupApp.BaseApi baseApi := v1.ApiGroupApp.BaseApi

View File

@ -9,7 +9,7 @@ import (
type WebsiteGroupRouter struct { type WebsiteGroupRouter struct {
} }
func (a *WebsiteGroupRouter) InitWebsiteGroupRouter(Router *gin.RouterGroup) { func (a *WebsiteGroupRouter) InitRouter(Router *gin.RouterGroup) {
groupRouter := Router.Group("groups") groupRouter := Router.Group("groups")
groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired()) groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())

View File

@ -9,7 +9,7 @@ import (
type HostRouter struct{} type HostRouter struct{}
func (s *HostRouter) InitHostRouter(Router *gin.RouterGroup) { func (s *HostRouter) InitRouter(Router *gin.RouterGroup) {
hostRouter := Router.Group("hosts"). hostRouter := Router.Group("hosts").
Use(middleware.JwtAuth()). Use(middleware.JwtAuth()).
Use(middleware.SessionAuth()). Use(middleware.SessionAuth()).

View File

@ -9,7 +9,7 @@ import (
type LogRouter struct{} type LogRouter struct{}
func (s *LogRouter) InitLogRouter(Router *gin.RouterGroup) { func (s *LogRouter) InitRouter(Router *gin.RouterGroup) {
operationRouter := Router.Group("logs") operationRouter := Router.Group("logs")
operationRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired()) operationRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())
baseApi := v1.ApiGroupApp.BaseApi baseApi := v1.ApiGroupApp.BaseApi

View File

@ -9,7 +9,7 @@ import (
type MonitorRouter struct{} type MonitorRouter struct{}
func (s *MonitorRouter) InitMonitorRouter(Router *gin.RouterGroup) { func (s *MonitorRouter) InitRouter(Router *gin.RouterGroup) {
monitorRouter := Router.Group("monitors"). monitorRouter := Router.Group("monitors").
Use(middleware.JwtAuth()). Use(middleware.JwtAuth()).
Use(middleware.SessionAuth()). Use(middleware.SessionAuth()).

View File

@ -9,7 +9,7 @@ import (
type NginxRouter struct { type NginxRouter struct {
} }
func (a *NginxRouter) InitNginxRouter(Router *gin.RouterGroup) { func (a *NginxRouter) InitRouter(Router *gin.RouterGroup) {
groupRouter := Router.Group("openresty") groupRouter := Router.Group("openresty")
groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired()) groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())

View File

@ -9,7 +9,7 @@ import (
type ProcessRouter struct { type ProcessRouter struct {
} }
func (f *ProcessRouter) InitProcessRouter(Router *gin.RouterGroup) { func (f *ProcessRouter) InitRouter(Router *gin.RouterGroup) {
processRouter := Router.Group("process") processRouter := Router.Group("process")
processRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired()) processRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())
baseApi := v1.ApiGroupApp.BaseApi baseApi := v1.ApiGroupApp.BaseApi

View File

@ -0,0 +1,7 @@
package router
import "github.com/gin-gonic/gin"
type CommonRouter interface {
InitRouter(Router *gin.RouterGroup)
}

View File

@ -9,7 +9,7 @@ import (
type RuntimeRouter struct { type RuntimeRouter struct {
} }
func (r *RuntimeRouter) InitRuntimeRouter(Router *gin.RouterGroup) { func (r *RuntimeRouter) InitRouter(Router *gin.RouterGroup) {
groupRouter := Router.Group("runtimes") groupRouter := Router.Group("runtimes")
groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired()) groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())

View File

@ -8,7 +8,7 @@ import (
type SettingRouter struct{} type SettingRouter struct{}
func (s *SettingRouter) InitSettingRouter(Router *gin.RouterGroup) { func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) {
router := Router.Group("settings"). router := Router.Group("settings").
Use(middleware.JwtAuth()). Use(middleware.JwtAuth()).
Use(middleware.SessionAuth()) Use(middleware.SessionAuth())

View File

@ -9,7 +9,7 @@ import (
type TerminalRouter struct{} type TerminalRouter struct{}
func (s *TerminalRouter) InitTerminalRouter(Router *gin.RouterGroup) { func (s *TerminalRouter) InitRouter(Router *gin.RouterGroup) {
terminalRouter := Router.Group("terminals"). terminalRouter := Router.Group("terminals").
Use(middleware.JwtAuth()). Use(middleware.JwtAuth()).
Use(middleware.SessionAuth()). Use(middleware.SessionAuth()).

View File

@ -9,7 +9,7 @@ import (
type ToolboxRouter struct{} type ToolboxRouter struct{}
func (s *ToolboxRouter) InitToolboxRouter(Router *gin.RouterGroup) { func (s *ToolboxRouter) InitRouter(Router *gin.RouterGroup) {
toolboxRouter := Router.Group("toolbox"). toolboxRouter := Router.Group("toolbox").
Use(middleware.JwtAuth()). Use(middleware.JwtAuth()).
Use(middleware.SessionAuth()). Use(middleware.SessionAuth()).

View File

@ -9,7 +9,7 @@ import (
type WebsiteRouter struct { type WebsiteRouter struct {
} }
func (a *WebsiteRouter) InitWebsiteRouter(Router *gin.RouterGroup) { func (a *WebsiteRouter) InitRouter(Router *gin.RouterGroup) {
groupRouter := Router.Group("websites") groupRouter := Router.Group("websites")
groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired()) groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())

View File

@ -9,7 +9,7 @@ import (
type WebsiteAcmeAccountRouter struct { type WebsiteAcmeAccountRouter struct {
} }
func (a *WebsiteAcmeAccountRouter) InitWebsiteAcmeAccountRouter(Router *gin.RouterGroup) { func (a *WebsiteAcmeAccountRouter) InitRouter(Router *gin.RouterGroup) {
groupRouter := Router.Group("websites/acme") groupRouter := Router.Group("websites/acme")
groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired()) groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())

View File

@ -6,7 +6,10 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func (a *WebsiteDnsAccountRouter) InitWebsiteCARouter(Router *gin.RouterGroup) { type WebsiteCARouter struct {
}
func (a *WebsiteCARouter) InitRouter(Router *gin.RouterGroup) {
groupRouter := Router.Group("websites/ca") groupRouter := Router.Group("websites/ca")
groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired()) groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())

View File

@ -9,7 +9,7 @@ import (
type WebsiteDnsAccountRouter struct { type WebsiteDnsAccountRouter struct {
} }
func (a *WebsiteDnsAccountRouter) InitWebsiteDnsAccountRouter(Router *gin.RouterGroup) { func (a *WebsiteDnsAccountRouter) InitRouter(Router *gin.RouterGroup) {
groupRouter := Router.Group("websites/dns") groupRouter := Router.Group("websites/dns")
groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired()) groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())

View File

@ -9,7 +9,7 @@ import (
type WebsiteSSLRouter struct { type WebsiteSSLRouter struct {
} }
func (a *WebsiteSSLRouter) InitWebsiteSSLRouter(Router *gin.RouterGroup) { func (a *WebsiteSSLRouter) InitRouter(Router *gin.RouterGroup) {
groupRouter := Router.Group("websites/ssl") groupRouter := Router.Group("websites/ssl")
groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired()) groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())

View File

@ -16,3 +16,5 @@ VITE_BUILD_GZIP = false
# 是否删除生产环境 console # 是否删除生产环境 console
VITE_DROP_CONSOLE = true VITE_DROP_CONSOLE = true
PANEL_XPACK = false

View File

@ -5,9 +5,11 @@ NODE_ENV = 'development'
VITE_API_URL = '/api/v1' VITE_API_URL = '/api/v1'
# 是否生成包预览文件 # 是否生成包预览文件
VITE_REPORT = true VITE_REPORT = false
# 是否开启gzip压缩 # 是否开启gzip压缩
VITE_BUILD_GZIP = true VITE_BUILD_GZIP = true
VITE_DROP_CONSOLE = true VITE_DROP_CONSOLE = true
PANEL_XPACK = true

View File

@ -11,3 +11,5 @@ VITE_REPORT = true
VITE_BUILD_GZIP = true VITE_BUILD_GZIP = true
VITE_DROP_CONSOLE = true VITE_DROP_CONSOLE = true
PANEL_XPACK = true

View File

@ -1,4 +1,4 @@
import axios, { AxiosInstance, AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'; import axios, { AxiosInstance, AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
import { ResultData } from '@/api/interface'; import { ResultData } from '@/api/interface';
import { ResultEnum } from '@/enums/http-enum'; import { ResultEnum } from '@/enums/http-enum';
import { checkStatus } from './helper/check-status'; import { checkStatus } from './helper/check-status';
@ -32,7 +32,7 @@ class RequestHttp {
} }
return { return {
...config, ...config,
}; } as InternalAxiosRequestConfig<any>;
}, },
(error: AxiosError) => { (error: AxiosError) => {
return Promise.reject(error); return Promise.reject(error);

View File

@ -1,7 +1,11 @@
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'; import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import { Layout } from '@/routers/constant'; import { Layout } from '@/routers/constant';
const modules = import.meta.globEager('./modules/*.ts'); let modules = import.meta.globEager('./modules/*.ts');
const xpackModules = import.meta.globEager('../xpack/frontend/routers/*.ts');
modules = { ...modules, ...xpackModules };
console.log(modules);
const homeRouter: RouteRecordRaw = { const homeRouter: RouteRecordRaw = {
path: '/', path: '/',

View File

@ -20,6 +20,7 @@ declare interface ViteEnv {
VITE_PROXY_URL: string; VITE_PROXY_URL: string;
VITE_BUILD_GZIP: boolean; VITE_BUILD_GZIP: boolean;
VITE_REPORT: boolean; VITE_REPORT: boolean;
PANEL_XPACK: boolean;
} }
declare interface RouterButton { declare interface RouterButton {