Skip to content

Added dev-proxy.sh, dev-start.sh#42155

Open
iAbhi001 wants to merge 1 commit intoanthropics:mainfrom
iAbhi001:main
Open

Added dev-proxy.sh, dev-start.sh#42155
iAbhi001 wants to merge 1 commit intoanthropics:mainfrom
iAbhi001:main

Conversation

@iAbhi001
Copy link
Copy Markdown

@iAbhi001 iAbhi001 commented Apr 1, 2026


PR Title

docs: add remote backend proxy pattern for hybrid dev environments

Description

This PR addresses #41406 by introducing a standard pattern for developing frontends locally while connecting to a remote backend (API/DB).

The current Preview MCP documentation assumes a unified local stack. However, developers often face resource constraints (RAM/CPU) or utilize shared development servers, necessitating a bridge between the local Vite dev server and a remote gateway.

Changes

  • Added dev-proxy.mjs: A lightweight, zero-dependency Node.js reverse proxy using node:http.
  • Added dev-start.sh: A cross-platform shell wrapper to orchestrate the lifecycle of both the proxy and Vite.
  • Includes specific fixes for:
    • Node.js 24 IPv6 resolution: Forces family: 4 to prevent connection hangs.
    • macOS Compatibility: Uses POSIX-compliant wait instead of wait -n (which requires Bash 4+).
    • CORS handling: Manually injects headers to allow local development against remote origins.

Architecture

The pattern implements the following flow:
BrowserVite (5173)dev-proxy (5174)Remote Gateway (8080)


Technical Implementation Details

The Proxy (dev-proxy.mjs)

  • Port: 5174
  • Feature: Explicitly handles OPTIONS preflight requests and adds Access-Control-Allow-Origin headers.
  • Reliability: Uses the family: 4 option in http.request to bypass known DNS resolution issues in Vite 7/Node 24 environments.

The Orchestrator (dev-start.sh)

  • Uses a trap mechanism to ensure that stopping the script (Ctrl+C) kills both the proxy and Vite processes simultaneously, preventing "ghost" processes from occupying ports.
  • Configurable via GATEWAY_HOST environment variable.

How to Test

  1. Place dev-proxy.mjs and dev-start.sh in the scripts/ directory.
  2. Set your remote IP: export GATEWAY_HOST="your.remote.ip".
  3. Run ./scripts/dev-start.sh.
  4. Verify that API calls from the frontend are successfully routed to the remote backend through the proxy.

Checklist

  • Tested on macOS (Bash 3.2 compatibility)
  • Tested on Linux
  • Verified Node.js 24 compatibility
  • No new dependencies added (uses native node:http)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant