Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twenty-parents-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workflow/core": patch
---

Add CORS headers to endpoints health check response
25 changes: 24 additions & 1 deletion packages/core/src/runtime/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ export async function getAllWorkflowRunEvents(runId: string): Promise<Event[]> {
return allEvents;
}

/**
* CORS headers for health check responses.
* Allows the observability UI to check endpoint health from a different origin.
*/
const HEALTH_CHECK_CORS_HEADERS = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, OPTIONS, GET, HEAD',
'Access-Control-Allow-Headers': 'Content-Type',
};

/**
* Wraps a request/response handler and adds a health check "mode"
* based on the presence of a `__health` query parameter.
Expand All @@ -45,9 +55,22 @@ export function withHealthCheck(
const url = new URL(req.url);
const isHealthCheck = url.searchParams.has('__health');
if (isHealthCheck) {
// Handle CORS preflight for health check
if (req.method === 'OPTIONS') {
return new Response(null, {
status: 204,
headers: HEALTH_CHECK_CORS_HEADERS,
});
}
return new Response(
`Workflow DevKit "${url.pathname}" endpoint is healthy`,
{ status: 200, headers: { 'Content-Type': 'text/plain' } }
{
status: 200,
headers: {
'Content-Type': 'text/plain',
...HEALTH_CHECK_CORS_HEADERS,
},
}
);
}
return await handler(req);
Expand Down
Loading