Skip to content

Commit a7b58e2

Browse files
Merge pull request #48 from adamgall/health-check
Add health check route
2 parents 869fb5e + 0b95bd5 commit a7b58e2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ Alternatively, you can use `go get`:
6060
go get github.com/danielgtaylor/apisprout
6161
```
6262

63+
## Extra Features
64+
65+
### Remote Reload
66+
67+
If your API spec is loaded from a remote URL, you can live-reload it by hitting the `/__reload` endpoint.
68+
69+
### Health Check
70+
71+
A simple endpoint which returns status code `200` is available at `/__health`. This endpoint successfully returns `200` even if `--validate-server` is turned on, and the endpoint is being accessed from a non-validated host.
72+
6373
## Contributing
6474

6575
Contributions are very welcome. Please open a tracking issue or pull request and we can work to get things merged in.

apisprout.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,12 @@ func server(cmd *cobra.Command, args []string) {
441441
})
442442
}
443443

444+
// Add a health check route which returns 200
445+
http.HandleFunc("/__health", func(w http.ResponseWriter, r *http.Request) {
446+
w.WriteHeader(200)
447+
log.Printf("Health check")
448+
})
449+
444450
// Register our custom HTTP handler that will use the router to find
445451
// the appropriate OpenAPI operation and try to return an example.
446452
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {

0 commit comments

Comments
 (0)