feat: make admin path configurable (#322)

pull/348/head
Zwb 1 year ago committed by GitHub
parent a7249f34ec
commit b201e0dfe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -28,4 +28,5 @@ mysql:
sonic:
mode: "development"
work_dir: "./" # 不填默认为当前路径,用来存放日志文件、数据库文件、模板、上传的附件等(The default is the current directory. Used to store log files, database files, templates, upload files)
log_dir: "./logs" # 不填则使用work_dir 路径下的log路径 (If it is empty, use the "log" path under work_dir)
log_dir: "./logs" # 不填则使用work_dir 路径下的log路径 (If it is empty, use the "log" path under work_dir)
admin_url_path: admin_random

@ -30,6 +30,8 @@ func NewConfig() *Config {
viper.SetConfigName("config")
}
viper.SetDefault("sonic.admin_url_path", "admin")
conf := &Config{}
if err := viper.ReadInConfig(); err != nil {
panic(err)

@ -49,4 +49,5 @@ type Sonic struct {
TemplateDir string `mapstructure:"template_dir"`
ThemeDir string
AdminResourcesDir string
AdminURLPath string `mapstructure:"admin_url_path"`
}

@ -86,7 +86,12 @@ func (s *StartListener) printStartInfo(ctx context.Context) error {
site := logger.BlueBold + "Sonic started at " + blogURL + logger.Reset
log.Info(site)
fmt.Println(site)
adminSite := logger.BlueBold + "Sonic admin started at " + blogURL + "/admin" + logger.Reset
adminURLPath, err := s.optionService.GetAdminURLPath(ctx)
if err != nil {
return err
}
adminSite := logger.BlueBold + "Sonic admin started at " + blogURL + "/" + adminURLPath + logger.Reset
log.Info(adminSite)
fmt.Println(adminSite)
return nil

@ -60,7 +60,8 @@ func (v *ViewHandler) Install(ctx *gin.Context) {
if isInstall {
return
}
ctx.Redirect(http.StatusTemporaryRedirect, "admin/#install")
adminURLPath, _ := v.OptionService.GetAdminURLPath(ctx)
ctx.Redirect(http.StatusTemporaryRedirect, adminURLPath+"/#install")
}
func (v *ViewHandler) Logo(ctx *gin.Context) (interface{}, error) {

@ -36,7 +36,7 @@ func (s *Server) RegisterRouters() {
})
{
staticRouter := router.Group("/")
staticRouter.StaticFS("admin", gin.Dir(s.Config.Sonic.AdminResourcesDir, false))
staticRouter.StaticFS(s.Config.Sonic.AdminURLPath, gin.Dir(s.Config.Sonic.AdminResourcesDir, false))
staticRouter.StaticFS("/css", gin.Dir(filepath.Join(s.Config.Sonic.AdminResourcesDir, "css"), false))
staticRouter.StaticFS("/js", gin.Dir(filepath.Join(s.Config.Sonic.AdminResourcesDir, "js"), false))
staticRouter.StaticFS("/images", gin.Dir(filepath.Join(s.Config.Sonic.AdminResourcesDir, "images"), false))

@ -469,3 +469,7 @@ func (o *optionServiceImpl) GetAttachmentType(ctx context.Context) consts.Attach
return consts.AttachmentTypeLocal
}
}
func (o *optionServiceImpl) GetAdminURLPath(ctx context.Context) (string, error) {
return o.Config.Sonic.AdminURLPath, nil
}

@ -32,6 +32,7 @@ type OptionService interface {
GetLinkPrefix(ctx context.Context) (string, error)
GetSheetPrefix(ctx context.Context) (string, error)
GetAttachmentType(ctx context.Context) consts.AttachmentType
GetAdminURLPath(ctx context.Context) (string, error)
}
type ClientOptionService interface {

Loading…
Cancel
Save