summaryrefslogtreecommitdiff
path: root/caddyconfig/httpcaddyfile
diff options
context:
space:
mode:
Diffstat (limited to 'caddyconfig/httpcaddyfile')
-rw-r--r--caddyconfig/httpcaddyfile/builtins.go60
1 files changed, 19 insertions, 41 deletions
diff --git a/caddyconfig/httpcaddyfile/builtins.go b/caddyconfig/httpcaddyfile/builtins.go
index a88c27c..2c5a2d7 100644
--- a/caddyconfig/httpcaddyfile/builtins.go
+++ b/caddyconfig/httpcaddyfile/builtins.go
@@ -15,7 +15,6 @@
package httpcaddyfile
import (
- "encoding/json"
"fmt"
"html"
"net/http"
@@ -32,8 +31,8 @@ import (
func init() {
RegisterDirective("bind", parseBind)
- RegisterDirective("root", parseRoot) // TODO: isn't this a handler directive?
RegisterDirective("tls", parseTLS)
+ RegisterHandlerDirective("root", parseRoot)
RegisterHandlerDirective("redir", parseRedir)
RegisterHandlerDirective("respond", parseRespond)
RegisterHandlerDirective("route", parseRoute)
@@ -54,45 +53,6 @@ func parseBind(h Helper) ([]ConfigValue, error) {
return h.NewBindAddresses(lnHosts), nil
}
-// parseRoot parses the root directive. Syntax:
-//
-// root [<matcher>] <path>
-//
-func parseRoot(h Helper) ([]ConfigValue, error) {
- if !h.Next() {
- return nil, h.ArgErr()
- }
-
- matcherSet, ok, err := h.MatcherToken()
- if err != nil {
- return nil, err
- }
- if !ok {
- // no matcher token; oops
- h.Dispenser.Prev()
- }
-
- if !h.NextArg() {
- return nil, h.ArgErr()
- }
- root := h.Val()
- if h.NextArg() {
- return nil, h.ArgErr()
- }
-
- varsHandler := caddyhttp.VarsMiddleware{"root": root}
- route := caddyhttp.Route{
- HandlersRaw: []json.RawMessage{
- caddyconfig.JSONModuleObject(varsHandler, "handler", "vars", nil),
- },
- }
- if matcherSet != nil {
- route.MatcherSetsRaw = []caddy.ModuleMap{matcherSet}
- }
-
- return []ConfigValue{{Class: "route", Value: route}}, nil
-}
-
// parseTLS parses the tls directive. Syntax:
//
// tls [<email>|internal]|[<cert_file> <key_file>] {
@@ -350,6 +310,24 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
return configVals, nil
}
+// parseRoot parses the root directive. Syntax:
+//
+// root [<matcher>] <path>
+//
+func parseRoot(h Helper) (caddyhttp.MiddlewareHandler, error) {
+ var root string
+ for h.Next() {
+ if !h.Next() {
+ return nil, h.ArgErr()
+ }
+ root = h.Val()
+ if h.NextArg() {
+ return nil, h.ArgErr()
+ }
+ }
+ return caddyhttp.VarsMiddleware{"root": root}, nil
+}
+
// parseRedir parses the redir directive. Syntax:
//
// redir [<matcher>] <to> [<code>]