mirror of
https://github.com/certimate-go/certimate.git
synced 2026-07-20 21:01:41 +08:00
fix: #1342
This commit is contained in:
parent
e948ca5f79
commit
1d02567daf
109
main.go
109
main.go
@ -31,15 +31,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
var flagHttp string
|
||||
pflag.CommandLine = pflag.NewFlagSet(os.Args[0], pflag.ContinueOnError)
|
||||
pflag.CommandLine.Parse(os.Args[2:]) // skip the first two arguments: "main.go serve"
|
||||
pflag.StringVar(&flagHttp, "http", "127.0.0.1:8090", "HTTP server address")
|
||||
pflag.Parse()
|
||||
|
||||
migratecmd.MustRegister(pb, pb.RootCmd, migratecmd.Config{
|
||||
// enable auto creation of migration files when making collection changes in the Admin UI
|
||||
// (the isGoRun check is to enable it only during development)
|
||||
Automigrate: strings.HasPrefix(os.Args[0], os.TempDir()),
|
||||
})
|
||||
|
||||
@ -47,65 +39,70 @@ func main() {
|
||||
pb.RootCmd.AddCommand(cmd.NewVersionCommand(pb))
|
||||
pb.RootCmd.AddCommand(cmd.NewWinscCommand(pb))
|
||||
|
||||
switch os.Args[1] {
|
||||
case "serve":
|
||||
{
|
||||
pb.OnServe().BindFunc(func(e *core.ServeEvent) error {
|
||||
scheduler.Setup()
|
||||
workflow.Setup()
|
||||
routes.BindRouter(e.Router)
|
||||
isServeCmd := os.Args[1] == "serve"
|
||||
|
||||
if isServeCmd {
|
||||
var flagHttp string
|
||||
pflag.CommandLine = pflag.NewFlagSet(os.Args[0], pflag.ContinueOnError)
|
||||
pflag.CommandLine.Parse(os.Args[2:]) // skip the first two arguments: "main.go serve"
|
||||
pflag.StringVar(&flagHttp, "http", "127.0.0.1:8090", "HTTP server address")
|
||||
pflag.Parse()
|
||||
|
||||
pb.OnServe().BindFunc(func(e *core.ServeEvent) error {
|
||||
scheduler.Setup()
|
||||
workflow.Setup()
|
||||
routes.BindRouter(e.Router)
|
||||
return e.Next()
|
||||
})
|
||||
|
||||
pb.OnServe().Bind(&hook.Handler[*core.ServeEvent]{
|
||||
Func: func(e *core.ServeEvent) error {
|
||||
e.Router.
|
||||
GET("/{path...}", apis.Static(ui.DistDirFS, false)).
|
||||
Bind(apis.Gzip())
|
||||
return e.Next()
|
||||
})
|
||||
},
|
||||
Priority: 999,
|
||||
})
|
||||
|
||||
pb.OnServe().Bind(&hook.Handler[*core.ServeEvent]{
|
||||
Func: func(e *core.ServeEvent) error {
|
||||
e.Router.
|
||||
GET("/{path...}", apis.Static(ui.DistDirFS, false)).
|
||||
Bind(apis.Gzip())
|
||||
return e.Next()
|
||||
},
|
||||
Priority: 999,
|
||||
})
|
||||
pb.OnServe().BindFunc(func(e *core.ServeEvent) error {
|
||||
slog.Info("[CERTIMATE] Visit the website: http://" + flagHttp)
|
||||
return e.Next()
|
||||
})
|
||||
|
||||
pb.OnServe().BindFunc(func(e *core.ServeEvent) error {
|
||||
slog.Info("[CERTIMATE] Visit the website: http://" + flagHttp)
|
||||
return e.Next()
|
||||
})
|
||||
pb.OnBootstrap().BindFunc(func(e *core.BootstrapEvent) error {
|
||||
err := e.Next()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pb.OnBootstrap().BindFunc(func(e *core.BootstrapEvent) error {
|
||||
err := e.Next()
|
||||
if err != nil {
|
||||
settings := pb.Settings()
|
||||
if !settings.Batch.Enabled {
|
||||
settings.Batch.Enabled = true
|
||||
settings.Batch.MaxRequests = 1000
|
||||
settings.Batch.Timeout = 30
|
||||
if err := pb.Save(settings); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
settings := pb.Settings()
|
||||
if !settings.Batch.Enabled {
|
||||
settings.Batch.Enabled = true
|
||||
settings.Batch.MaxRequests = 1000
|
||||
settings.Batch.Timeout = 30
|
||||
if err := pb.Save(settings); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
pb.OnTerminate().BindFunc(func(e *core.TerminateEvent) error {
|
||||
pb.OnTerminate().BindFunc(func(e *core.TerminateEvent) error {
|
||||
if pb.IsBootstrapped() {
|
||||
workflow.Teardown()
|
||||
return e.Next()
|
||||
})
|
||||
|
||||
if err := cmd.Serve(pb); err != nil {
|
||||
slog.Error("[CERTIMATE] Serve failed.", slog.Any("error", err))
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
if err := pb.Execute(); err != nil {
|
||||
slog.Error("[CERTIMATE] Start failed.", slog.Any("error", err))
|
||||
}
|
||||
return e.Next()
|
||||
})
|
||||
}
|
||||
|
||||
if err := cmd.Serve(pb); err != nil {
|
||||
if isServeCmd {
|
||||
slog.Error("[CERTIMATE] Serve failed.", slog.Any("error", err))
|
||||
} else {
|
||||
slog.Error("[CERTIMATE] Start failed.", slog.Any("error", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user