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
15 changes: 15 additions & 0 deletions .changeset/mighty-squids-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@cloudflare/sandbox': patch
---

Add process readiness detection with port and log pattern waiting
The `Process` object returned by `startProcess()` now includes readiness methods:

- `process.waitForPort(port, options?)`: Wait for process to listen on a port
- Supports HTTP mode (default): checks endpoint returns expected status (200-399)
- Supports TCP mode: checks port accepts connections
- Configurable timeout, interval, path, and expected status

- `process.waitForLog(pattern, options?)`: Wait for pattern in process output
- Supports string or RegExp patterns
- Returns matching line and capture groups
46 changes: 15 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions packages/sandbox-container/src/handlers/port-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Port Handler
import type {
Logger,
PortCheckRequest,
PortCloseResult,
PortExposeResult,
PortListResult
Expand All @@ -25,6 +26,8 @@ export class PortHandler extends BaseHandler<Request, Response> {

if (pathname === '/api/expose-port') {
return await this.handleExpose(request, context);
} else if (pathname === '/api/port-check') {
return await this.handlePortCheck(request, context);
} else if (pathname === '/api/exposed-ports') {
return await this.handleList(request, context);
} else if (pathname.startsWith('/api/exposed-ports/')) {
Expand All @@ -51,6 +54,23 @@ export class PortHandler extends BaseHandler<Request, Response> {
);
}

private async handlePortCheck(
request: Request,
context: RequestContext
): Promise<Response> {
const body = await this.parseRequestBody<PortCheckRequest>(request);

const result = await this.portService.checkPortReady(body);

return new Response(JSON.stringify(result), {
status: 200,
headers: {
'Content-Type': 'application/json',
...context.corsHeaders
}
});
}

private async handleExpose(
request: Request,
context: RequestContext
Expand Down
Loading
Loading