I have a simple express backend which works fine hosting it via terminal and node app.js
- trying this command using the dev rig though, will throw some errors when I try to access the backend.
Without the dev rig I called my backend using http://localhost:4400/
from my frontend (which is being hosted via dev rig) - do I need to use another endpoint when hosting backend using dev rig?
Console throws the following error, might be false trail though.
Access to fetch at ‘http://localhost:4400/’ from origin ‘https://localhost:8080’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.
const express = require("express");
const bodyParser = require("body-parser");
const middlewares = require("./middlewares");
require("dotenv").config();
const app = express();
const port = 4400;
const jsonParser = bodyParser.json();
app.use(middlewares.headers);
app.use(jsonParser);
app.get("/", ((req, res) => {
res.send("Hello");
}))
app.listen(port);
const headersMiddleware = (req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE");
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Refresh_Token");
next();
};