stackblitz / webcontainer-docs

WebContainer API Documentation
MIT License
67 stars 22 forks source link

Native node backend capabilities #32

Open alper-batioglu opened 1 year ago

alper-batioglu commented 1 year ago

Describe the bug Hello, I am trying testing mongoDB connection from a webcontainer. But i was unable to get it working. After debugging I saw it gets stuck in dns.promises.resolveSrv call. It does not get resolved nor gets rejected. I checked the documentation and nothing mentions about native node limitations. So, I wonder if this is a bug or are there limitations.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://webcontainers.io/
  2. Click on 'index.js' editor portion of the page.
  3. paste the following script.
    
    import dns from "dns";

dns.promises.resolveSrv('_mongodb._tcp.cluster0.cb93mrj.mongodb.net').then(() => console.log('then')).catch(() => console.log('catch'));

console.log(Hello Node.js v${process.versions.node}!); setTimeout(() => console.log('time is up :('), 5000);



5. Click on "Run index.js" or type "node index.js" in the terminal portion of the screen and press enter.
6. See "Hello Node.js v16.14.2!" and "time is up :(" lines. But there is no catch neither then. Promise just gets vaporised.

**Expected behavior**
dns.promises.resolveSrv call returns a promise which should be either resolved or rejected.

**Screenshots**
<img width="862" alt="image" src="https://github.com/stackblitz/webcontainer-docs/assets/26070511/9eb06815-b3cf-48f2-9bfd-a877ae0e296d">

**Desktop (please complete the following information):**
 - OS: MacOS Ventura 13.3.1 (a)
 - Browser: Microsoft Edge
 - Version: Version 113.0.1774.35 (Official build) (arm64)
thienphanexcalibur commented 1 year ago

It seems the DNS layer is not working in native node webcontainer

thienphanexcalibur commented 1 year ago

@alper-batioglu refer to this answer of webcontainer maintainer https://github.com/stackblitz/webcontainer-core/issues/1106#issuecomment-1602232609

we don't support databases like Mongo out of the box, b/c that would require something akin to low-level networking in the browser (e.g. TCP/UDP sockets, DNS, etc.), which don't currently exist. We are thinking about ways around this, but we don't have any concrete roadmap about it. If you're interested, we can leave this open as a venue for updates in case anything changes.