mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 12:42:16 +01:00
feat(api): add dummy root route pointing to docs (#1099)
* feat(api): added dummy root route pointing to docs * test(api): root request test added * feat(api): added NoContent return for favicon from @gulien Co-authored-by: Julien Neuhart <neuhart.julien@gmail.com> * test(api): added favicon * lint(api): fix format * refactor(api): use %s for favicon.ico for consistency with /health * test(api): added new recorder for each check * docs(api): consistent comment for favicon --------- Co-authored-by: Julien Neuhart <neuhart.julien@gmail.com>
This commit is contained in:
@@ -483,6 +483,22 @@ func (a *Api) Start() error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Root route.
|
||||||
|
a.srv.GET(
|
||||||
|
a.rootPath,
|
||||||
|
func(c echo.Context) error {
|
||||||
|
return c.HTML(http.StatusOK, `Hey, this Gotenberg has no UI, it's an API. Head to the <a href="https://gotenberg.dev">documentation</a> to learn how to interact with it 🚀`)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// Favicon route.
|
||||||
|
a.srv.GET(
|
||||||
|
fmt.Sprintf("%s%s", a.rootPath, "favicon.ico"),
|
||||||
|
func(c echo.Context) error {
|
||||||
|
return c.NoContent(http.StatusNoContent)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
// Let's not forget the health check routes...
|
// Let's not forget the health check routes...
|
||||||
checks := append(a.healthChecks, health.WithTimeout(a.timeout))
|
checks := append(a.healthChecks, health.WithTimeout(a.timeout))
|
||||||
checker := health.NewChecker(checks...)
|
checker := health.NewChecker(checks...)
|
||||||
|
|||||||
@@ -866,15 +866,31 @@ func TestApi_Start(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// health requests.
|
// root request.
|
||||||
recorder := httptest.NewRecorder()
|
recorder := httptest.NewRecorder()
|
||||||
|
rootRequest := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||||
|
mod.srv.ServeHTTP(recorder, rootRequest)
|
||||||
|
if recorder.Code != http.StatusOK {
|
||||||
|
t.Errorf("expected %d status code but got %d", http.StatusOK, recorder.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
// favicon request.
|
||||||
|
recorder = httptest.NewRecorder()
|
||||||
|
faviconRequest := httptest.NewRequest(http.MethodGet, "/favicon.ico", nil)
|
||||||
|
mod.srv.ServeHTTP(recorder, faviconRequest)
|
||||||
|
if recorder.Code != http.StatusNoContent {
|
||||||
|
t.Errorf("expected %d status code but got %d", http.StatusNoContent, recorder.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
// health requests.
|
||||||
|
recorder = httptest.NewRecorder()
|
||||||
healthGetRequest := httptest.NewRequest(http.MethodGet, "/health", nil)
|
healthGetRequest := httptest.NewRequest(http.MethodGet, "/health", nil)
|
||||||
mod.srv.ServeHTTP(recorder, healthGetRequest)
|
mod.srv.ServeHTTP(recorder, healthGetRequest)
|
||||||
if recorder.Code != http.StatusOK {
|
if recorder.Code != http.StatusOK {
|
||||||
t.Errorf("expected %d status code but got %d", http.StatusOK, recorder.Code)
|
t.Errorf("expected %d status code but got %d", http.StatusOK, recorder.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recorder = httptest.NewRecorder()
|
||||||
healthHeadRequest := httptest.NewRequest(http.MethodHead, "/health", nil)
|
healthHeadRequest := httptest.NewRequest(http.MethodHead, "/health", nil)
|
||||||
mod.srv.ServeHTTP(recorder, healthHeadRequest)
|
mod.srv.ServeHTTP(recorder, healthHeadRequest)
|
||||||
if recorder.Code != http.StatusOK {
|
if recorder.Code != http.StatusOK {
|
||||||
@@ -882,6 +898,7 @@ func TestApi_Start(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// version request.
|
// version request.
|
||||||
|
recorder = httptest.NewRecorder()
|
||||||
versionRequest := httptest.NewRequest(http.MethodGet, "/version", nil)
|
versionRequest := httptest.NewRequest(http.MethodGet, "/version", nil)
|
||||||
mod.srv.ServeHTTP(recorder, versionRequest)
|
mod.srv.ServeHTTP(recorder, versionRequest)
|
||||||
if recorder.Code != http.StatusOK {
|
if recorder.Code != http.StatusOK {
|
||||||
|
|||||||
Reference in New Issue
Block a user