Skip to content

Commit bea3f88

Browse files
committed
docs(dev-v2): update instructions w/ REMIX_DEV_ORIGIN
1 parent cf97be3 commit bea3f88

1 file changed

Lines changed: 46 additions & 21 deletions

File tree

β€Ždocs/other-api/dev-v2.mdβ€Ž

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,23 @@ but CloudFlare does not support async I/O like `fetch` outside of request handli
136136

137137
Options priority order is: 1. flags, 2. config, 3. defaults.
138138

139-
| Option | flag | config | default |
140-
| --------------- | ------------------ | ---------------- | ------------------------------------------------- |
141-
| Command | `-c` / `--command` | `command` | `remix-serve <server build path>` |
142-
| No restart | `--no-restart` | `restart: false` | `restart: true` |
143-
| Scheme | `--scheme` | `scheme` | `https` if TLS key/cert are set, otherwise `http` |
144-
| Host | `--host` | `host` | `localhost` |
145-
| Port | `--port` | `port` | Dynamically chosen open port |
146-
| TLS key | `--tls-key` | `tlsKey` | N/A |
147-
| TLS certificate | `--tls-cert` | `tlsCert` | N/A |
139+
| Option | flag | config | default |
140+
| --------------- | ------------------ | ---------------- | --------------------------------- |
141+
| Command | `-c` / `--command` | `command` | `remix-serve <server build path>` |
142+
| No restart | `--no-restart` | `restart: false` | `restart: true` |
143+
| Port | `--port` | `port` | Dynamically chosen open port |
144+
| TLS key | `--tls-key` | `tlsKey` | N/A |
145+
| TLS certificate | `--tls-cert` | `tlsCert` | N/A |
148146

149147
<docs-info>
150148

151-
The scheme/host/port options only affect the Remix dev server, and **do not affect your app server**.
149+
The port option only affects the Remix dev server, and **does not affect your app server**.
152150
Your app will run on your app server's normal URL.
153151

154-
You most likely won't want to configure the scheme/host/port for the dev server,
155-
as those are implementation details used internally for hot updates.
156-
They exist in case you need fine-grain control, for example Docker networking or using specific open ports.
152+
You probably don't want to configure the port for the dev server,
153+
as it is an implementation detail used internally for hot updates.
154+
The port option exists in case you need fine-grain networking control,
155+
for example to setup Docker networking or use a specific open port for security purposes.
157156

158157
</docs-info>
159158

@@ -244,9 +243,11 @@ To use [Mock Service Worker][msw] in development, you'll need to:
244243
1. Run MSW as part of your app server
245244
2. Configure MSW to not mock internal "dev ready" messages to the dev server
246245

246+
`remix dev` will provide the `REMIX_DEV_ORIGIN` environment variable for use in your app server.
247+
247248
For example, if you are using [binode][binode] to integrate with MSW,
248249
make sure that the call to `binode` is within the `remix dev -c` subcommand.
249-
That way, the MSW server will have access to the `REMIX_DEV_HTTP_ORIGIN` environment variable:
250+
That way, the MSW server will have access to the `REMIX_DEV_ORIGIN` environment variable:
250251

251252
```json filename=package.json
252253
{
@@ -257,16 +258,16 @@ That way, the MSW server will have access to the `REMIX_DEV_HTTP_ORIGIN` environ
257258
}
258259
```
259260

260-
Next, you can use `REMIX_DEV_HTTP_ORIGIN` to let MSW forward internal "dev ready" messages on `/ping`:
261+
Next, you can use `REMIX_DEV_ORIGIN` to let MSW forward internal "dev ready" messages on `/ping`:
261262

262263
```ts
263264
import { rest } from "msw";
264265

266+
let REMIX_DEV_PING = new URL(process.env.REMIX_DEV_ORIGIN);
267+
REMIX_DEV_PING.pathname = "/ping";
268+
265269
export const server = setupServer(
266-
rest.post(
267-
`${process.env.REMIX_DEV_HTTP_ORIGIN}/ping`,
268-
(req) => req.passthrough()
269-
)
270+
rest.post(REMIX_DEV_PING.href, (req) => req.passthrough())
270271
// ... other request handlers go here ...
271272
);
272273
```
@@ -328,6 +329,31 @@ server.listen(port, () => {
328329
});
329330
```
330331

332+
### How to integrate with a reverse proxy
333+
334+
Let's say you have the app server and dev server both running on the same machine:
335+
336+
- App server πŸ‘‰ `http://localhost:1234`
337+
- Dev server πŸ‘‰ `http://localhost:5678`
338+
339+
Then, you setup a reverse proxy in front of the app server and dev server:
340+
341+
- Reverse proxy πŸ‘‰ `https://myhost`
342+
343+
But the internal HTTP and WebSocket connections to support hot updates will still try to reach the dev server's unproxied origin:
344+
345+
- Hot updates πŸ‘‰ `http://localhost:5678` / `ws://localhost:5678` ❌
346+
347+
To get the internal connections to point to the reverse proxy, you can use the `REMIX_DEV_ORIGIN` environment variable:
348+
349+
```sh
350+
REMIX_DEV_ORIGIN=https://myhost remix dev
351+
```
352+
353+
Now, hot updates will be sent correctly to the proxy:
354+
355+
- Hot updates πŸ‘‰ `https://myhost` / `wss://myhost` βœ…
356+
331357
### Troubleshooting
332358

333359
#### HMR: hot updates losing app state
@@ -336,8 +362,7 @@ Hot Module Replacement is supposed to keep your app's state around between hot u
336362
But in some cases React cannot distinguish between existing components being changed and new components being added.
337363
[React needs `key`s][react-keys] to disambiguate these cases and track changes when sibling elements are modified.
338364

339-
Additionally, when adding or removing hooks, React Refresh treats that as a brand new component.
340-
So if you add `useLoaderData` to your component, you may lose state local to that component.
365+
Additionally, when adding or removing hooks, React Refresh treats that as a brand new component. So if you add `useLoaderData` to your component, you may lose state local to that component.
341366

342367
These are limitations of React and [React Refresh][react-refresh], not Remix.
343368

0 commit comments

Comments
Β (0)