I deployed a web page using Angular 6 and Node 10 on Ubuntu Server 1 (v16.04. with ip address 1.2.3.4:3000). And I am using MariaDB on another server (Ubuntu Server 2, same version as Server 1. with ip address 1.2.3.5:3306). So, the current working architecture is the web page sends request to DB via Node and DB sends response back to the web page via Node as well. There is no problem in that.
Now, I want to allow other people to access the web page via port forwarding. So, if anyone comes through my public ip and some port (say, 5.6.7.8:6000), I want them to access the full web page. Port forwarding is set up so that if anyone comes to 5.6.7.8:6000, they are forwarded to 1.2.3.4:3000 (But, url shows 5.6.7.8:6000). When I tried, I can get to web page via 5.6.7.8:6000, but when I try to login (trying to send request to DB via Node), it gives CORS error.
Access to XMLHttpRequest at 'http://Server1-ip/api/some-api' from origin 'http://public-ip' has been blocked by CORS policy: The request client is not a secure context and the resource is in more-private address space
private
.
From error message, I get that I am sending request from public ip, so it is blocked since it is not recognized and not safe. So, I am using cors module in node like below, but it is not solving CORS issue.
import express from 'express'
import cors from 'cors'
// other imports
const app = express();
app.use(cors());
// other lines
At first, I specified the public ip like so, but it did not work either.
app.use(cors({ origin: 'http://5.6.7.8:6000' })) // tried with and without port
How can I fix the CORS error in port forwarding?
Suggested link deals with development environments, and I am working in production environments. The selected answer talks about disabling chrome settings at first, and then installing certificates, but from what I understand, that has to be done in each individual user's chrome. Although there are some comments regarding production environments, they are not definitive. I want to know how to solve CORS issue in production mode, where a user (coming from public ip) accesses a web that is deployed on more secure server ip.