Skip to content

Commit

Permalink
Add Variable replace possibility
Browse files Browse the repository at this point in the history
  • Loading branch information
git001 committed May 4, 2022
1 parent 06d4f72 commit ff58739
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
caddy
buildenv_*

# vscode
*vscode
*.code-workspace
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ As an handler within a route.
"handler": "exec",
// command to execute
"command": "git",
// command arguments
"args": ["pull", "origin", "master"],
// command arguments it's also possible to use
// caddy variables like {http.request.uuid}
"args": ["pull", "origin", "master", "# {http.request.uuid}"],

// [optional] directory to run the command from. Default is the current directory.
"directory": "/home/user/site/public",
Expand Down
6 changes: 6 additions & 0 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func (m Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddy
Error string `json:"error,omitempty"`
}

repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)

for index, argument := range m.Args {
m.Args[index] = repl.ReplaceAll(argument, "")
}

err := m.run()

if err == nil {
Expand Down

0 comments on commit ff58739

Please sign in to comment.