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;