mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-07-04 17:06:49 +00:00
Add endpoints to return nginx config from disk
This commit is contained in:
@ -164,6 +164,45 @@ func DeleteHost() func(http.ResponseWriter, *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetHostNginxConfig will return a Host's nginx config from disk
|
||||
// Route: GET /hosts/{hostID}/nginx-config
|
||||
// Route: GET /hosts/{hostID}/nginx-config.txt
|
||||
func GetHostNginxConfig(format string) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
var hostID int
|
||||
if hostID, err = getURLParamInt(r, "hostID"); err != nil {
|
||||
h.ResultErrorJSON(w, r, http.StatusBadRequest, err.Error(), nil)
|
||||
return
|
||||
}
|
||||
|
||||
item, err := host.GetByID(hostID)
|
||||
switch err {
|
||||
case sql.ErrNoRows:
|
||||
h.ResultErrorJSON(w, r, http.StatusNotFound, "Not found", nil)
|
||||
case nil:
|
||||
// Get the config from disk
|
||||
content, nErr := nginx.GetHostConfigContent(item)
|
||||
if nErr != nil {
|
||||
h.ResultErrorJSON(w, r, http.StatusBadRequest, nErr.Error(), nil)
|
||||
return
|
||||
}
|
||||
if format == "text" {
|
||||
h.ResultResponseText(w, r, http.StatusOK, content)
|
||||
return
|
||||
}
|
||||
|
||||
j := struct {
|
||||
Content string `json:"content"`
|
||||
}{Content: content}
|
||||
|
||||
h.ResultResponseJSON(w, r, http.StatusOK, j)
|
||||
default:
|
||||
h.ResultErrorJSON(w, r, http.StatusBadRequest, err.Error(), nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func configureHost(h host.Model) {
|
||||
err := jobqueue.AddJob(jobqueue.Job{
|
||||
Name: "NginxConfigureHost",
|
||||
|
Reference in New Issue
Block a user