Skip to content

Commit 81a409f

Browse files
Add /health endpoint (#490)
1 parent 6ed4cef commit 81a409f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/restate-sdk/src/endpoint/handlers/generic.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,21 @@ export class GenericHandler implements RestateHandler {
137137
}
138138

139139
if (parsed.type === "unknown") {
140-
const msg = `Invalid path: path doesn't end in /invoke/SvcName/handlerName and also not in /discover: ${path}`;
140+
const msg = `Invalid path. Allowed are /health, or /discover, or /invoke/SvcName/handlerName, but was: ${path}`;
141141
this.endpoint.rlog.trace(msg);
142142
return this.toErrorResponse(404, msg);
143143
}
144144

145+
if (parsed.type === "health") {
146+
return {
147+
body: OnceStream(new TextEncoder().encode("OK")),
148+
headers: {
149+
"content-type": "application/text",
150+
"x-restate-server": X_RESTATE_SERVER,
151+
},
152+
statusCode: 200,
153+
};
154+
}
145155
if (parsed.type === "discover") {
146156
return this.handleDiscovery(request.headers["accept"]);
147157
}

packages/restate-sdk/src/types/components.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ export class WorkflowHandler implements ComponentHandler {
269269
export type PathComponents =
270270
| InvokePathComponents
271271
| { type: "discover" }
272+
| { type: "health" }
272273
| { type: "unknown"; path: string };
273274

274275
export type InvokePathComponents = {
@@ -292,5 +293,8 @@ export function parseUrlComponents(urlPath?: string): PathComponents {
292293
if (fragments.length > 0 && fragments[fragments.length - 1] === "discover") {
293294
return { type: "discover" };
294295
}
296+
if (fragments.length > 0 && fragments[fragments.length - 1] === "health") {
297+
return { type: "health" };
298+
}
295299
return { type: "unknown", path: urlPath };
296300
}

0 commit comments

Comments
 (0)