0

I'm getting an error (CORS request rejected: https://localhost:3000/users) when trying register a new user. The example comes from the book Building APIs with node.js, Chapter 12. I'm using Firefox on Ubuntu. I've searched online for away to disable CORS within Firefox but nothing is working. I'm not sure if I should be changing a setting in Firefox or what code I could add to the example code. Please help point me in the right direction.

import NTask from "../ntask.js";
import Template from "../templates/signup.js";

class Signup extends NTask {
  constructor(body) {
    super();
    this.body = body;
  }
  render() {
    this.body.innerHTML = Template.render();
    this.body.querySelector("[data-name]").focus();
    this.addEventListener();
  }
  addEventListener() {
    this.formSubmit();
  }
  formSubmit() {
    const form = this.body.querySelector("form");
    form.addEventListener("submit", (e) => {
      e.preventDefault();
      const name = e.target.querySelector("[data-name]");
      const email = e.target.querySelector("[data-email]");
      const password = e.target.querySelector("[data-password]");
      const opts = {
        method: "POST",
        url: `${this.URL}/users`,
        json: true,
        body: {
          name: name.value,
          email: email.value,
          password: password.value
        }
      };
      this.request(opts, (err, resp, data) => {
        if (err || resp.status === 412) {
          alert("IF: " + err);
          this.emit("error", err);
        } else {
          alert("ELSE")
          this.emit("signup", date);
        }
      });
    });
  }
}

module.exports = Signup;
3
  • if you are looking for only disabling in Firefox browser, try CORS disabling firefox extensions Commented Feb 23, 2020 at 3:06
  • I tried setting security.fileuri.strict_origin_policy to false and installed cors everywhere, neither one worked. Commented Feb 23, 2020 at 3:29
  • 1
    you have to allow the origin in your backend. Commented Feb 23, 2020 at 4:08

1 Answer 1

1

I think I found my answer, I skipped chapters 10 & 11, 11 being about CORS in the API (Titled: Preparing the Production Environment).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.