Skip to content

Commit 0a2328c

Browse files
authored
Don't require auth for healthz (#2055)
* Don't require authentication for healthz endpoint * Add FAQ entry for /healthz
1 parent e44e574 commit 0a2328c

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

doc/FAQ.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [How does code-server decide what workspace or folder to open?](#how-does-code-server-decide-what-workspace-or-folder-to-open)
2020
- [How do I debug issues with code-server?](#how-do-i-debug-issues-with-code-server)
2121
- [Heartbeat File](#heartbeat-file)
22+
- [Healthz endpoint](#healthz-endpoint)
2223
- [How does the config file work?](#how-does-the-config-file-work)
2324
- [Blank screen on iPad?](#blank-screen-on-ipad)
2425
- [Isn't an install script piped into sh insecure?](#isnt-an-install-script-piped-into-sh-insecure)
@@ -242,6 +243,20 @@ older than X minutes, kill `code-server`.
242243

243244
[#1636](https://github.com/cdr/code-server/issues/1636) will make the experience here better.
244245

246+
## Healthz endpoint
247+
248+
`code-server` exposes an endpoint at `/healthz` which can be used to check
249+
whether `code-server` is up without triggering a heartbeat. The response will
250+
include a status (`alive` or `expired`) and a timestamp for the last heartbeat
251+
(defaults to `0`). This endpoint does not require authentication.
252+
253+
```json
254+
{
255+
"status": "alive",
256+
"lastHeartbeat": 1599166210566
257+
}
258+
```
259+
245260
## How does the config file work?
246261

247262
When `code-server` starts up, it creates a default config file in `~/.config/code-server/config.yaml` that looks

src/node/app/health.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import * as http from "http"
2-
import { HttpCode, HttpError } from "../../common/http"
3-
import { HttpProvider, HttpResponse, Route, Heart, HttpProviderOptions } from "../http"
1+
import { HttpProvider, HttpResponse, Heart, HttpProviderOptions } from "../http"
42

53
/**
64
* Check the heartbeat.
@@ -10,23 +8,14 @@ export class HealthHttpProvider extends HttpProvider {
108
super(options)
119
}
1210

13-
public async handleRequest(route: Route, request: http.IncomingMessage): Promise<HttpResponse> {
14-
if (!this.authenticated(request)) {
15-
if (this.isRoot(route)) {
16-
return { redirect: "/login", query: { to: route.fullPath } }
17-
}
18-
throw new HttpError("Unauthorized", HttpCode.Unauthorized)
19-
}
20-
21-
const result = {
11+
public async handleRequest(): Promise<HttpResponse> {
12+
return {
2213
cache: false,
2314
mime: "application/json",
2415
content: {
2516
status: this.heart.alive() ? "alive" : "expired",
2617
lastHeartbeat: this.heart.lastHeartbeat,
2718
},
2819
}
29-
30-
return result
3120
}
3221
}

0 commit comments

Comments
 (0)