Skip to main content

render_mock_server_binary

Function render_mock_server_binary 

Source
pub fn render_mock_server_binary() -> String
Expand description

Generate the src/main.rs for the standalone mock server binary.

The binary:

  • Reads all *.json fixture files from a fixtures directory (default ../../fixtures).
  • For each fixture that has a mock_response field, registers a route at /fixtures/{fixture_id} returning the configured status/body/SSE chunks.
  • Binds to 127.0.0.1:0 (random port), prints MOCK_SERVER_URL=http://... to stdout, then waits until stdin is closed for clean teardown.
  • Fixtures that declare host-root paths (/robots.txt, /sitemap.*, etc.) get their own dedicated listener so the crawler can fetch them from the host root. A second line MOCK_SERVERS={...} (sorted JSON object) maps fixture_id → base URL for those.

This binary is intended for cross-language e2e suites (WASM, Node) that spawn it as a child process and read the URL from its stdout.