mirror of
https://github.com/php/frankenphp.git
synced 2026-03-24 00:52:11 +01:00
fix: nomercure build tag (#2212)
- Fixes nomercure tag build - Conditionally addds the mercure route and mercure project import Fixes https://github.com/php/frankenphp/issues/2209 I am by no means a go developer, feel free to use this or not :) --------- Signed-off-by: tehmaestro <alexnegrila89@gmail.com> Co-authored-by: Alexander Stecher <45872305+AlliBalliBaba@users.noreply.github.com>
This commit is contained in:
@@ -2,12 +2,17 @@
|
||||
|
||||
package caddy
|
||||
|
||||
type mercureContext struct {
|
||||
}
|
||||
import (
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
||||
)
|
||||
|
||||
func (f *FrankenPHPModule) configureHotReload(_ *FrankenPHPApp) error {
|
||||
return nil
|
||||
type mercureContext struct {
|
||||
}
|
||||
|
||||
func (f *FrankenPHPModule) assignMercureHub(_ caddy.Context) {
|
||||
}
|
||||
|
||||
func createMercureRoute() (caddyhttp.Route, error) {
|
||||
return caddyhttp.Route{}, nil
|
||||
}
|
||||
|
||||
@@ -3,7 +3,12 @@
|
||||
package caddy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig"
|
||||
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
||||
"github.com/dunglas/frankenphp"
|
||||
"github.com/dunglas/mercure"
|
||||
mercureCaddy "github.com/dunglas/mercure/caddy"
|
||||
@@ -31,3 +36,36 @@ func (f *FrankenPHPModule) assignMercureHub(ctx caddy.Context) {
|
||||
f.Workers[i] = wc
|
||||
}
|
||||
}
|
||||
|
||||
func createMercureRoute() (caddyhttp.Route, error) {
|
||||
mercurePublisherJwtKey := os.Getenv("MERCURE_PUBLISHER_JWT_KEY")
|
||||
if mercurePublisherJwtKey == "" {
|
||||
return caddyhttp.Route{}, errors.New(`The "MERCURE_PUBLISHER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`)
|
||||
}
|
||||
|
||||
mercureSubscriberJwtKey := os.Getenv("MERCURE_SUBSCRIBER_JWT_KEY")
|
||||
if mercureSubscriberJwtKey == "" {
|
||||
return caddyhttp.Route{}, errors.New(`The "MERCURE_SUBSCRIBER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`)
|
||||
}
|
||||
|
||||
mercureRoute := caddyhttp.Route{
|
||||
HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject(
|
||||
mercureCaddy.Mercure{
|
||||
PublisherJWT: mercureCaddy.JWTConfig{
|
||||
Alg: os.Getenv("MERCURE_PUBLISHER_JWT_ALG"),
|
||||
Key: mercurePublisherJwtKey,
|
||||
},
|
||||
SubscriberJWT: mercureCaddy.JWTConfig{
|
||||
Alg: os.Getenv("MERCURE_SUBSCRIBER_JWT_ALG"),
|
||||
Key: mercureSubscriberJwtKey,
|
||||
},
|
||||
},
|
||||
"handler",
|
||||
"mercure",
|
||||
nil,
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
return mercureRoute, nil;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mercureModule "github.com/dunglas/mercure/caddy"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig"
|
||||
caddycmd "github.com/caddyserver/caddy/v2/cmd"
|
||||
@@ -253,34 +251,10 @@ func cmdPHPServer(fs caddycmd.Flags) (int, error) {
|
||||
}
|
||||
|
||||
if mercure {
|
||||
mercurePublisherJwtKey := os.Getenv("MERCURE_PUBLISHER_JWT_KEY")
|
||||
if mercurePublisherJwtKey == "" {
|
||||
panic(`The "MERCURE_PUBLISHER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`)
|
||||
}
|
||||
|
||||
mercureSubscriberJwtKey := os.Getenv("MERCURE_SUBSCRIBER_JWT_KEY")
|
||||
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: mercurePublisherJwtKey,
|
||||
},
|
||||
SubscriberJWT: mercureModule.JWTConfig{
|
||||
Alg: os.Getenv("MERCURE_SUBSCRIBER_JWT_ALG"),
|
||||
Key: mercureSubscriberJwtKey,
|
||||
},
|
||||
},
|
||||
"handler",
|
||||
"mercure",
|
||||
nil,
|
||||
),
|
||||
},
|
||||
}
|
||||
mercureRoute, err := createMercureRoute()
|
||||
if err != nil {
|
||||
return caddy.ExitCodeFailedStartup, err
|
||||
}
|
||||
|
||||
subroute.Routes = append(caddyhttp.RouteList{mercureRoute}, subroute.Routes...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user