bykof / cordova-plugin-webserver

A webserver plugin for cordova
Other
124 stars 49 forks source link

Website accessible from a browser, but not from fetch? #74

Open patrickinminneapolis opened 1 year ago

patrickinminneapolis commented 1 year ago

I followed the instructions and chrome can hit: http://127.0.01:8080 but I cannot hit it from javascript that created the server.

  start();  // this creates the server which serves up data to chrome ;

// the next line -- I try to see if I can get any data from it -- it always errors : 
        setInterval(() => {
          fetch("http://127.0.0.1:8080")
            .then((response) => {
              console.log("fetch appeared to succeed");
              return response.text(); // not json()
            })
            .then((data) => console.log(data))
            .catch((err) => {
              console.log("there was an error", err);
            });
        }, 10 * 1000);

Is there any way to hit the webserver from the code that creates the webserver? I am trying to make a CORS-PROXY

patrickinminneapolis commented 1 year ago

I got my fetch working with 127.0.0.1:8080 after I added

webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);