I am facing following error :
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://192.168.1.217:3001/api/login?id=a&ps=x&ip=20.85.153.255&loc=Washington%2022747%20Virginia%20United%20States. (Reason: CORS request did not succeed). Status code: (null).
My setup is
1) with this setup , project not able to communicate between port 80 ( front end ) to 3001 ( backend ) as orinial request is coming from external IP .
2) and error message The Same Origin Policy disallows reading the remote resource
3) I use nodejs express
const cors = require('cors');
const app = express();
app.use(cors({ origin: '*' }));
app.use("/", express.static(path.join(__dirname, "angular")));
app.use((req, res, next) => {
// res.setHeader("Access-Control-Allow-Origin", "*");
// res.setHeader("Access-Control-Allow-Credentials", "true");
// res.setHeader("Access-Control-Allow-Headers", "Content-Type, accept , Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");
// res.setHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE, OPTIONS");
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Allow-Headers", "Content-Type, accept , Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");
res.header("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE, OPTIONS");
next();
});
Not sure what mistake I am doing here