facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.28k stars 24.35k forks source link

dev-middleware: Redefine "serverBaseUrl" as server-relative, '/json/list' by requestor #47628

Open robhogan opened 2 days ago

robhogan commented 2 days ago

Summary: serverBaseUrl is currently documented as:

The base URL to the dev server, as addressible from the local developer machine

This is problematic in general because dev-middleware on a server doesn't necessarily know about where clients might be reaching it from, how tunnels or port-forwards are set up, etc., and this can change over the lifetime of the server and vary between clients.

Indeed, our own use of serverBaseUrl from both community-cli-plugin and internally simply sets it to the host and port the dev server is listening on - ie it's the address of the dev server accessible from the server.

This PR changes the docs, redefining serverBaseUrl, to match the way we currently specify it.

One usage where we do want the previously documented behaviour is in responses to /json/list (getPageDescriptions) where the URLs in the response should be reachable by a browser requesting /json/list.

Here, we use the request (host header, etc.) to attempt to get working base URL.

History: It should be mentioned that this is the latest in a series of changes like this:

Learning from those:

This sets up some subsequent changes for more robust handling of tunnelled connections.

Changelog: [General][Breaking] dev-middleware: Frameworks should specify serverBaseUrl relative to the middleware host.

Differential Revision: D65974487

facebook-github-bot commented 2 days ago

This pull request was exported from Phabricator. Differential Revision: D65974487