|
| 1 | +--- |
| 2 | +title: Proxy traffic via your local network |
| 3 | +description: How to proxy traffic from your remote runners to your local network. This helps to run tests against local servers. |
| 4 | +--- |
| 5 | + |
| 6 | +import { Steps, Tabs, TabItem, Code, Aside } from '@astrojs/starlight/components'; |
| 7 | + |
| 8 | +import { Image } from "astro:assets"; |
| 9 | +import LocalTraffic from "../../../assets/local-server-traffic.png"; |
| 10 | + |
| 11 | +Servers that you want to test against that are either running locally or within a private network are not automatically exposed to the internet. |
| 12 | +These servers are not reachable by default from the remotely running Playwright instances. |
| 13 | +Trying to reach them without this extra setup, would likely result in connection errors in your tests. |
| 14 | + |
| 15 | + |
| 16 | +When this happens, we need a method of shuttling traffic between the remote runners and the servers running on your local network. |
| 17 | + |
| 18 | +<Image |
| 19 | + src={LocalTraffic} |
| 20 | + alt="A diagram of the traffic from the remote runners through your CLI to your local server." |
| 21 | + height={500} |
| 22 | +/> |
| 23 | + |
| 24 | +Endform has the ability to connect the remote Playwright runners to the servers on your local network via direct, hole-punched, encrypted, peer-to-peer connections. |
| 25 | +We can do this by utilizing the [iroh network](https://www.iroh.computer/docs/overview). |
| 26 | + |
| 27 | +## Setting up endform to proxy traffic |
| 28 | + |
| 29 | +<Aside> |
| 30 | +Proxying traffic via your local network is currently in alpha, we would be grateful for any feedback you have on this feature. |
| 31 | +</Aside> |
| 32 | + |
| 33 | + |
| 34 | +<Steps> |
| 35 | + |
| 36 | +1. ### Install the addon package |
| 37 | + |
| 38 | + In order for traffic to be proxied, we need to install the extra `endform-proxy-network` package in the same place as you installed the main `endform` CLI. |
| 39 | + |
| 40 | + <Tabs syncKey="pkg"> |
| 41 | + <TabItem label="npm"> |
| 42 | + ```sh |
| 43 | + npm install endform-proxy-network |
| 44 | + ``` |
| 45 | + </TabItem> |
| 46 | + <TabItem label="pnpm"> |
| 47 | + ```sh |
| 48 | + pnpm install endform-proxy-network |
| 49 | + ``` |
| 50 | + </TabItem> |
| 51 | + <TabItem label="Yarn"> |
| 52 | + ```sh |
| 53 | + yarn install endform-proxy-network |
| 54 | + ``` |
| 55 | + </TabItem> |
| 56 | + <TabItem label="Bun"> |
| 57 | + ```sh |
| 58 | + bun install endform-proxy-network |
| 59 | + ``` |
| 60 | + </TabItem> |
| 61 | + </Tabs> |
| 62 | + |
| 63 | +2. ### Configure which traffic to proxy. |
| 64 | + |
| 65 | + #### As a playwright `webServer` |
| 66 | + If you want to run your local server as a [playwright `webServer`](https://playwright.dev/docs/api/class-testconfig#test-config-web-server) |
| 67 | + then you're done! Leave your web server configuration as is, and we will automatically proxy the traffic to your local server. |
| 68 | + |
| 69 | + #### With your own custom server |
| 70 | + If you're running a server outside of playwright - that's fine. You can tell endform which traffic to proxy by using a `endform.jsonc` file. |
| 71 | + |
| 72 | + <Code language="json" title="endform.jsonc" code={` |
| 73 | + { |
| 74 | + "proxyNetworkHosts": [ |
| 75 | + "<loopback>", |
| 76 | + "*.my-special-domain.com" |
| 77 | + ] |
| 78 | + } |
| 79 | + `} /> |
| 80 | + |
| 81 | + You can read more about the `proxyNetworkHosts` configuration in the [endform config reference](/docs/reference/endform-config#proxy-network-hosts). |
| 82 | + |
| 83 | +3. ### Run your tests! |
| 84 | + |
| 85 | + That's it! You can now run your tests as normal, and the traffic will be proxied via the cli to your target server. |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +</Steps> |
0 commit comments