Skip to content

Commit

Permalink
Simplify env checks
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup committed Jan 21, 2024
1 parent 2f9808c commit 31e62db
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions caddy/php-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ For more advanced use cases, see https://github.com/dunglas/frankenphp/blob/main
cmd.Flags().StringArrayP("worker", "w", []string{}, "Worker script")
cmd.Flags().BoolP("access-log", "a", false, "Enable the access log")
cmd.Flags().BoolP("debug", "v", false, "Enable verbose debug logs")
cmd.Flags().BoolP("mercure", "m", false, "Enable the mercure module")
cmd.Flags().BoolP("mercure", "m", false, "Enable the built-in Mercure.rocks hub")
cmd.Flags().BoolP("no-compress", "", false, "Disable Zstandard and Gzip compression")
cmd.RunE = caddycmd.WrapCommandFuncForCobra(cmdPHPServer)
},
Expand Down Expand Up @@ -199,24 +199,27 @@ func cmdPHPServer(fs caddycmd.Flags) (int, error) {
}

if mercure {
if _, exists := os.LookupEnv("MERCURE_PUBLISHER_JWT_KEY"); !exists {
panic("The \"MERCURE_PUBLISHER_JWT_KEY\" environment variable must be set to use mercure")
mercurePublisherJwtKey := os.Getenv("MERCURE_PUBLISHER_JWT_KEY")
mercureSubscriberJwtKey := os.Getenv("MERCURE_SUBSCRIBER_JWT_KEY")

if mercurePublisherJwtKey == "" {
panic(`The "MERCURE_PUBLISHER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`)
}

if _, exists := os.LookupEnv("MERCURE_SUBSCRIBER_JWT_KEY"); !exists {
panic("The \"MERCURE_SUBSCRIBER_JWT_KEY\" environment variable must be set to use mercure")
if mercureSubscriberJwtKey == "" {
panic(`The "MERCURE_SUBSCRIBER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`)
}

mercureRoute := caddyhttp.Route{
HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject(
mercureModule.Mercure{
PublisherJWT: mercureModule.JWTConfig{
Alg: os.Getenv("MERCURE_PUBLISHER_JWT_ALG"),
Key: os.Getenv("MERCURE_PUBLISHER_JWT_KEY"),
Key: mercurePublisherJwtKey,
},
SubscriberJWT: mercureModule.JWTConfig{
Alg: os.Getenv("MERCURE_SUBSCRIBER_JWT_ALG"),
Key: os.Getenv("MERCURE_SUBSCRIBER_JWT_KEY"),
Key: mercureSubscriberJwtKey,
},
},
"handler",
Expand Down

0 comments on commit 31e62db

Please sign in to comment.