diff --git a/.gitignore b/.gitignore index 9464ba6..a0eaeb5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ caddy buildenv_* + +# vscode +*vscode +*.code-workspace \ No newline at end of file diff --git a/README.md b/README.md index 99f2a53..cf407a7 100644 --- a/README.md +++ b/README.md @@ -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", diff --git a/middleware.go b/middleware.go index ebe5be1..5493eb0 100644 --- a/middleware.go +++ b/middleware.go @@ -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 {