stackblitz / webcontainer-core

Dev environments. In your web app.
https://webcontainers.io
MIT License
3.93k stars 171 forks source link

How to communicate between the host and the container? #1617

Open henophilia opened 3 days ago

henophilia commented 3 days ago

I have a use case where I would like my main application to call API endpoints exposed by the application running within the Webcontainer and vice versa. When my host server is running locally at localhost:3000 and I call fetch("http://localhost:3000/api/...") from within the Webcontainer, obviously it doesn't work, because that API endpoint does not exist within the container.

I already thought of a few rather "hacky" solutions, such as:

But there must be a better solution for this kind of basic HTTP communication between host and container. How do I do this?