summaryrefslogtreecommitdiff
path: root/nex.go
diff options
context:
space:
mode:
Diffstat (limited to 'nex.go')
-rw-r--r--nex.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/nex.go b/nex.go
index d64f588..a8a5a9e 100644
--- a/nex.go
+++ b/nex.go
@@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
+ "strings"
"github.com/go-kit/log/level"
@@ -11,6 +12,7 @@ import (
"tildegit.org/tjp/sliderule/contrib/fs"
"tildegit.org/tjp/sliderule/logging"
"tildegit.org/tjp/sliderule/nex"
+ "tildegit.org/tjp/syw"
)
func buildNexServer(server Server, config *Configuration) (sr.Server, error) {
@@ -57,6 +59,8 @@ func addNexRoute(router *sr.Router, route RouteDirective) {
buildAndAddRoute(router, route, func(route RouteDirective) sr.Handler {
return cgi.NexCGIDirectory(route.FsPath, route.URLPath, route.Modifiers.ExecCmd)
})
+ case "git":
+ addNexGitRoute(router, route)
}
}
@@ -84,3 +88,19 @@ func addNexStaticRoute(router *sr.Router, route RouteDirective) {
return sr.FallthroughHandler(handlers...)
})
}
+
+func addNexGitRoute(router *sr.Router, route RouteDirective) {
+ buildAndAddRoute(router, route, func(route RouteDirective) sr.Handler {
+ subrouter := syw.NexRouter(route.FsPath, route.Modifiers.Templates)
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
+ reqclone := cloneRequest(request)
+ reqclone.Path = strings.TrimPrefix(reqclone.Path, route.URLPath)
+
+ handler, params := subrouter.Match(reqclone)
+ if handler == nil {
+ return nil
+ }
+ return handler.Handle(context.WithValue(ctx, sr.RouteParamsKey, params), request)
+ })
+ })
+}