config.go 701 B

123456789101112131415161718192021222324252627282930313233
  1. package nginx_controller
  2. import (
  3. "fmt"
  4. "github.com/astaxie/beego/logs"
  5. config2 "nginx-ui/server/config"
  6. )
  7. type ConfigController struct {
  8. BaseController
  9. }
  10. // Get 前端的配置文件
  11. func (c *ConfigController) Get() {
  12. config := config2.Config
  13. oauth2Config := config2.OauthConfig
  14. var sso = "false"
  15. if oauth2Config.Enable {
  16. sso = "true"
  17. }
  18. js := fmt.Sprintf(" window.CONFIG = {\n baseApi: '%s',\n SSO: %s }", config.BaseApi, sso)
  19. output := c.Ctx.Output
  20. output.SetStatus(200)
  21. output.Header("Cache-Control", "no-cache")
  22. output.Header("content-type", "text/javascript")
  23. err := c.Ctx.Output.Body([]byte(js))
  24. if err != nil {
  25. logs.Error("config.js fail", err)
  26. return
  27. }
  28. }