Skip to content

Commit

Permalink
Allow __reload usage for file as well
Browse files Browse the repository at this point in the history
  • Loading branch information
cboitel committed Feb 6, 2020
1 parent 7f560ea commit 2cb3237
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions apisprout.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,27 +714,25 @@ func server(cmd *cobra.Command, args []string) {

rr.Set(router)

if strings.HasPrefix(uri, "http") {
http.HandleFunc("/__reload", func(w http.ResponseWriter, r *http.Request) {
log.Printf("🌙 Reloading %s\n", uri)
data, err = loadSwaggerFromUri(uri)
if err == nil {
if s, r, err := load(uri, data); err == nil {
swagger = s
rr.Set(r)
}
}
if err == nil {
log.Printf("Reloaded from %s", uri)
w.WriteHeader(200)
w.Write([]byte("reloaded"))
} else {
log.Printf("ERROR: %s", err)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("error while reloading"))
http.HandleFunc("/__reload", func(w http.ResponseWriter, r *http.Request) {
log.Printf("🌙 Reloading %s\n", uri)
data, err = loadSwaggerFromUri(uri)
if err == nil {
if s, r, err := load(uri, data); err == nil {
swagger = s
rr.Set(r)
}
})
}
}
if err == nil {
log.Printf("Reloaded from %s", uri)
w.WriteHeader(200)
w.Write([]byte("reloaded"))
} else {
log.Printf("ERROR: %s", err)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("error while reloading"))
}
})

// Add a health check route which returns 200
http.HandleFunc("/__health", func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 2cb3237

Please sign in to comment.