Skip to content

Commit

Permalink
Merge pull request #2117 from goodrain/V6.1
Browse files Browse the repository at this point in the history
feat: v6.1.0 release
  • Loading branch information
zzzhangqi authored Dec 31, 2024
2 parents eede68d + 2b979e5 commit 4bfa0bf
Show file tree
Hide file tree
Showing 12 changed files with 609 additions and 218 deletions.
22 changes: 22 additions & 0 deletions api/api_routers/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package api_routers

import (
"net/http"

"github.com/gin-gonic/gin"
)

type RouteStruct struct {
// Add any necessary fields here
}

func (r *RouteStruct) SetRoutes(engine *gin.Engine) {
// 应用 CORS 中间件到所有路由
engine.Use(func(c *gin.Context) {
controller.CORS(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c.Next()
})).ServeHTTP(c.Writer, c.Request)
})

// ... 其余路由注册代码
}
40 changes: 36 additions & 4 deletions api/api_routers/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
package websocket

import (
"net/http"

"github.com/go-chi/chi"
"github.com/goodrain/rainbond/api/controller"
"github.com/goodrain/rainbond/pkg/component/eventlog"
"github.com/sirupsen/logrus"
)

// Routes routes
Expand Down Expand Up @@ -64,10 +67,39 @@ func PackageBuildRoutes() chi.Router {
// FileOperateRoutes 共享存储的文件操作路由
func FileOperateRoutes() chi.Router {
r := chi.NewRouter()
r.Get("/download/{fileName}", controller.GetFileManage().Get)
r.Options("/download/{fileName}", controller.GetFileManage().Get)
r.Post("/upload", controller.GetFileManage().Get)
r.Options("/upload", controller.GetFileManage().Get)
r.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
logrus.Debugf("处理请求: %s %s", r.Method, r.URL.Path)

// 获取 Origin
origin := r.Header.Get("Origin")
if origin == "" {
origin = "*"
}

// 设置 CORS 头
w.Header().Set("Access-Control-Allow-Origin", origin)
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Custom-Header, X-Requested-With")
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Max-Age", "3600")

// 处理 OPTIONS 请求
if r.Method == "OPTIONS" {
logrus.Debug("处理 OPTIONS 预检请求")
w.WriteHeader(http.StatusOK)
return
}

next.ServeHTTP(w, r)
})
})

r.Route("/", func(r chi.Router) {
r.Get("/download/{fileName}", controller.GetFileManage().DownloadFile)
r.Post("/upload", controller.GetFileManage().UploadFile)
r.Post("/mkdir", controller.GetFileManage().CreateDirectory)
})
return r
}

Expand Down
34 changes: 17 additions & 17 deletions api/controller/apigateway/api_gateway_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,26 @@ func (g Struct) CreateHTTPAPIRoute(w http.ResponseWriter, r *http.Request) {

routeName = strings.ReplaceAll(routeName, "/", "p-p")
routeName = strings.ReplaceAll(routeName, "*", "s-s")
name := r.URL.Query().Get("name")
//name := r.URL.Query().Get("name")

for _, host := range apisixRouteHTTP.Match.Hosts {
labels[host] = "host"
labelSelector := host + "=host"
roueList, err := c.ApisixRoutes(tenant.Namespace).List(r.Context(), v1.ListOptions{
LabelSelector: labelSelector,
})
if err != nil {
logrus.Errorf("list check route failure: %v", err)
httputil.ReturnBcodeError(r, w, bcode.ErrRouteNotFound)
return
}
parts := strings.Split(name, "-")
bName := strings.Join(parts[:len(parts)-1], "-")
if roueList != nil && len(roueList.Items) > 0 && r.URL.Query().Get("intID")+roueList.Items[0].Name != bName && !defaultDomain {
logrus.Errorf("list check route failure: %v", err)
httputil.ReturnBcodeError(r, w, bcode.ErrRouteExist)
return
}
//labelSelector := host + "=host"
//roueList, err := c.ApisixRoutes(tenant.Namespace).List(r.Context(), v1.ListOptions{
// LabelSelector: labelSelector,
//})
//if err != nil {
// logrus.Errorf("list check route failure: %v", err)
// httputil.ReturnBcodeError(r, w, bcode.ErrRouteNotFound)
// return
//}
//parts := strings.Split(name, "-")
//bName := strings.Join(parts[:len(parts)-1], "-")
//if roueList != nil && len(roueList.Items) > 0 && r.URL.Query().Get("intID")+roueList.Items[0].Name != bName && !defaultDomain {
// logrus.Errorf("list check route failure: %v", err)
// httputil.ReturnBcodeError(r, w, bcode.ErrRouteExist)
// return
//}
}

apisixRouteHTTP.Name = uuid.NewV4().String()[0:8] //每次都让他变化,让 apisix controller去更新
Expand Down
1 change: 1 addition & 0 deletions api/controller/apigateway/api_gateway_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (g Struct) CreateAPIService(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, marshalApisixUpstream(create))
return
}
logrus.Errorf("create ApisixUpstreams failure: %v", err)
// 去更新 yaml
get, err := c.ApisixUpstreams(tenant.Namespace).Get(r.Context(), chi.URLParam(r, "name"), v1.GetOptions{})
if err != nil {
Expand Down
Loading

0 comments on commit 4bfa0bf

Please sign in to comment.