You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

filter.go 1.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2023 The casbin Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package routers
  15. import (
  16. "fmt"
  17. "net/http"
  18. "strings"
  19. "github.com/astaxie/beego"
  20. "github.com/astaxie/beego/context"
  21. "github.com/casbin/casibase/util"
  22. )
  23. func TransparentStatic(ctx *context.Context) {
  24. urlPath := ctx.Request.URL.Path
  25. if strings.HasPrefix(urlPath, "/api/") {
  26. return
  27. }
  28. landingFolder := beego.AppConfig.String("landingFolder")
  29. if landingFolder != "" {
  30. if urlPath == "" || urlPath == "/" || urlPath == "/about" {
  31. http.ServeFile(ctx.ResponseWriter, ctx.Request, fmt.Sprintf("../%s/web/build/index.html", landingFolder))
  32. return
  33. }
  34. landingPath := fmt.Sprintf("../%s/web/build%s", landingFolder, urlPath)
  35. if util.FileExist(landingPath) {
  36. http.ServeFile(ctx.ResponseWriter, ctx.Request, landingPath)
  37. return
  38. }
  39. }
  40. path := "web/build"
  41. if urlPath == "/" {
  42. path += "/index.html"
  43. } else {
  44. path += urlPath
  45. }
  46. if util.FileExist(path) {
  47. http.ServeFile(ctx.ResponseWriter, ctx.Request, path)
  48. } else {
  49. http.ServeFile(ctx.ResponseWriter, ctx.Request, "web/build/index.html")
  50. }
  51. }

基于Casbin的开源AI领域知识库平台