mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: use backend for /healthz page (#4938)
This commit is contained in:
@@ -233,6 +233,8 @@ func New(options *Options) *API {
|
||||
httpmw.CSRF(options.SecureAuthCookie),
|
||||
)
|
||||
|
||||
r.Get("/healthz", func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("OK")) })
|
||||
|
||||
apps := func(r chi.Router) {
|
||||
r.Use(
|
||||
tracing.Middleware(api.TracerProvider),
|
||||
|
||||
@@ -2,6 +2,7 @@ package coderd_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"strconv"
|
||||
@@ -114,3 +115,17 @@ func TestDERPLatencyCheck(t *testing.T) {
|
||||
defer res.Body.Close()
|
||||
require.Equal(t, http.StatusOK, res.StatusCode)
|
||||
}
|
||||
func TestHealthz(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := coderdtest.New(t, nil)
|
||||
|
||||
res, err := client.Request(context.Background(), http.MethodGet, "/healthz", nil)
|
||||
require.NoError(t, err)
|
||||
defer res.Body.Close()
|
||||
|
||||
require.Equal(t, http.StatusOK, res.StatusCode)
|
||||
body, err := io.ReadAll(res.Body)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "OK", string(body))
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
|
||||
|
||||
assertRoute := map[string]RouteCheck{
|
||||
// These endpoints do not require auth
|
||||
"GET:/healthz": {NoAuthorize: true},
|
||||
"GET:/api/v2": {NoAuthorize: true},
|
||||
"GET:/api/v2/buildinfo": {NoAuthorize: true},
|
||||
"GET:/api/v2/users/first": {NoAuthorize: true},
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Locator, Page } from "@playwright/test"
|
||||
import { BasePom } from "./BasePom"
|
||||
|
||||
export class HealthzPage extends BasePom {
|
||||
constructor(baseURL: string | undefined, page: Page) {
|
||||
super(baseURL, "/healthz", page)
|
||||
}
|
||||
|
||||
getOk(): Locator {
|
||||
const locator = this.page.locator("text=ok")
|
||||
return locator
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { test } from "@playwright/test"
|
||||
import { HealthzPage } from "../pom/HealthzPage"
|
||||
|
||||
test("Healthz is available without authentication", async ({
|
||||
baseURL,
|
||||
page,
|
||||
}) => {
|
||||
const healthzPage = new HealthzPage(baseURL, page)
|
||||
await page.goto(healthzPage.url, { waitUntil: "networkidle" })
|
||||
await healthzPage.getOk().waitFor({ state: "visible" })
|
||||
})
|
||||
@@ -30,7 +30,6 @@ const NotFoundPage = lazy(() => import("./pages/404Page/404Page"))
|
||||
const CliAuthenticationPage = lazy(
|
||||
() => import("./pages/CliAuthPage/CliAuthPage"),
|
||||
)
|
||||
const HealthzPage = lazy(() => import("./pages/HealthzPage/HealthzPage"))
|
||||
const AccountPage = lazy(
|
||||
() => import("./pages/UserSettingsPage/AccountPage/AccountPage"),
|
||||
)
|
||||
@@ -107,7 +106,6 @@ export const AppRouter: FC = () => {
|
||||
|
||||
<Route path="login" element={<LoginPage />} />
|
||||
<Route path="setup" element={<SetupPage />} />
|
||||
<Route path="healthz" element={<HealthzPage />} />
|
||||
<Route
|
||||
path="cli-auth"
|
||||
element={
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { FC } from "react"
|
||||
|
||||
/**
|
||||
* HealthzPage is a page that is available without authentication that is used
|
||||
* for reporting whether or not the Dashboard is online. It should be
|
||||
* accessible by humans and services.
|
||||
*/
|
||||
export const HealthzPage: FC = () => <div>ok</div>
|
||||
|
||||
export default HealthzPage
|
||||
Reference in New Issue
Block a user