mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-20 14:13:23 +00:00
Replaces beego's ControllerRegister, filter chain and context with the native web package end to end. The controllers, filters and routes are retyped from beego.Context/beego.Controller to their web equivalents (web.Context mirrors beego's API, so the swap is mechanical), and the 307 explicit routes register on a shared routers.App (web.Router). The dead NSInclude namespace is dropped: without a generated commentsRouter it registered nothing. - controllers/base.go embeds web.Controller; the 4 streaming/util controllers, the 17 filters, util/cookie.go and object/record.go take *web.Context. - routers.InstallFilters inserts the 14 BeforeRouter + 2 AfterExec filters on App in the same order the standalone used; bootstrap and the route tests share it. - The session provider binds through App.UseSessions (its Store matches web.Store); Bootstrap publishes App as the request handler instead of beego.BeeApp.Handlers. - web gains the Controller compatibility surface the handlers use: EnableRender, GetFile, Context.SetCookie/Output.Cookie; RunMode defaults to prod (compact ServeJSON), matching the runtime default. The /swagger static (beego SetStaticPath) is dropped — the edge serves statics. Verified on SQLite (UseMemoryDB): /v1/cloud/* rewrites and dispatches, the /v1/iam/* alias is selective (in-set dispatches, out-of-set 404s), an unauthenticated gated /v1/cloud/get-providers is denied 401/403 before dispatch, and the real filter chain short-circuits on auth-reject in order. go build ./... and the web/routers/controllers/route tests are green; the beego module stays until the session and lifecycle cuts.
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
// Copyright 2023-2025 Hanzo AI Inc. All Rights Reserved.
|
|
// Portions Copyright 2025 The OpenAgent Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package util
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/hanzoai/ai/conf"
|
|
"github.com/hanzoai/ai/web"
|
|
)
|
|
|
|
func AppendWebConfigCookie(ctx *web.Context) error {
|
|
webConfig := conf.GetWebConfig()
|
|
|
|
jsonWebConfig, err := json.Marshal(webConfig)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
ctx.SetCookie("jsonWebConfig", string(jsonWebConfig))
|
|
return nil
|
|
}
|