mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 08:03:49 +01:00
caddy wip (#330)
This commit is contained in:
parent
8a9d91aa2c
commit
f3dd6c0602
@ -1,8 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/caddyserver/caddy/v2"
|
"github.com/caddyserver/caddy/v2"
|
||||||
|
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,17 +19,36 @@ type caddyCommand struct {
|
|||||||
|
|
||||||
func newCaddyCommand() *caddyCommand {
|
func newCaddyCommand() *caddyCommand {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "caddy",
|
Use: "caddy <configPath>",
|
||||||
Short: "Run an embedded caddy backend",
|
Short: "Run an embedded caddy backend",
|
||||||
Args: cobra.ExactArgs(0),
|
Args: cobra.ExactArgs(1),
|
||||||
}
|
}
|
||||||
command := &caddyCommand{cmd: cmd}
|
command := &caddyCommand{cmd: cmd}
|
||||||
cmd.Run = command.run
|
cmd.Run = command.run
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *caddyCommand) run(_ *cobra.Command, _ []string) {
|
func (cmd *caddyCommand) run(_ *cobra.Command, args []string) {
|
||||||
caddy.Run(&caddy.Config{})
|
if err := caddy.Run(&caddy.Config{}); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile(args[0])
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
var adapter caddyfile.Adapter
|
||||||
|
cfg, warn, err := adapter.Adapt(data, map[string]interface{}{"filename": args[0]})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
for _, w := range warn {
|
||||||
|
fmt.Println(w.Message)
|
||||||
|
}
|
||||||
|
fmt.Printf("cfg: %v\n", cfg)
|
||||||
|
if err := caddy.Load(cfg, true); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
time.Sleep(30 * time.Minute)
|
time.Sleep(30 * time.Minute)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
:2015 {
|
servers :2015 {
|
||||||
route / {
|
route / {
|
||||||
visitor_ip "stderr"
|
visitor_ip "stderr"
|
||||||
}
|
}
|
||||||
respond "hello, world!"
|
respond "hello, world!"
|
||||||
|
protocols h1 h2c
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user