ora
ora

Reputation: 163

express and fetch: TypeError: NetworkError when attempting to fetch resource

I am using express, fetch and firefox. This is the code

async updateTutorial() {
const requestOptions = {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(this.currentTutorial)
    };

  await fetch("https://localhost:9000/tutorial/update" , requestOptions);


}

In Firefox I see this error: TypeError: NetworkError when attempting to fetch resource I do not know what kind of problem it is.

Upvotes: 2

Views: 29462

Answers (4)

ora
ora

Reputation: 163

I replaced the form tag with a div. Now there is no error. I have forgotten to mention that I get this log stamp:

[HMR] Waiting for update signal from WDS...

Upvotes: 1

MasterMind
MasterMind

Reputation: 1013

First of all, you must use http instead of https.

To fix the cors error, you have to specify mode:"no-cors" in request options.

async updateTutorial() {
 
          const requestOptions = {
            method: "POST",
            mode: "no-cors",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify(this.tutorial)
        } 

        await fetch("http://localhost:9000/tutorial/update" , requestOptions);
   }

I hope this helps. Let me know if you face any issues.

Upvotes: 6

ora
ora

Reputation: 163

I am using now this:

async updateTutorial() {
 
          const requestOptions = {
            method: "POST",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify(this.tutorial)
        } 

        await fetch("http://localhost:9000/tutorial/update" , requestOptions);
   }

In Firefox I get the same error, in Edge and Chrome it works. I have only one AddIn in Firefox installed from HP. This I can't deinstall.

Upvotes: 1

manjish
manjish

Reputation: 105

You are using https://localhost:9000/tutorial/update. For localhost use http://localhost:9000/tutorial/update

Upvotes: 0

Related Questions