web container - How to communicate between the host and a WebContainer? - Stack Overflow

I have a use case where I would like my main application to call API endpoints exposed by the applicati

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:

  • Writing a file to the WebContainer's file system whenever I want to communicate with it, and polling for changes within the WebContainer.
  • Using some sort of reverse proxy (e.g. ngrok), so that e.g. "myapp.example" is forwarded to my host application running on localhost, and then I could just fetch "myapp.example" from within the WebContainer. I already tried it out and this does actually work using ngrok, but it feels much more complicated than necessary.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745570815a4633671.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信