Skip to content

Commit ce4098e

Browse files
authored
Merge pull request #17 from git001/2022-05-04_add-arg-placeholder
Add Variable replace possibility
2 parents 06d4f72 + ff58739 commit ce4098e

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
caddy
22
buildenv_*
3+
4+
# vscode
5+
*vscode
6+
*.code-workspace

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ As an handler within a route.
129129
"handler": "exec",
130130
// command to execute
131131
"command": "git",
132-
// command arguments
133-
"args": ["pull", "origin", "master"],
132+
// command arguments it's also possible to use
133+
// caddy variables like {http.request.uuid}
134+
"args": ["pull", "origin", "master", "# {http.request.uuid}"],
134135

135136
// [optional] directory to run the command from. Default is the current directory.
136137
"directory": "/home/user/site/public",

middleware.go

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ func (m Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddy
4545
Error string `json:"error,omitempty"`
4646
}
4747

48+
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
49+
50+
for index, argument := range m.Args {
51+
m.Args[index] = repl.ReplaceAll(argument, "")
52+
}
53+
4854
err := m.run()
4955

5056
if err == nil {

0 commit comments

Comments
 (0)