I’m having cors issues deploying my ionic app and my server on node, express on a linux VPS server. My configuration in my index.ts is as follows:
server.app.use(cors({ origin:['IP_server:80','http://IP_server/login', 'http://IP_server', 'IP_server/*', 'localhost:80', 'localhost', '127.0.0.1'], credentials:true }));
I have deployed the ionic application in nginx and when I write the IP address of the server it correctly opens the application redirecting to http://IP_server/login but when I try to log in it tells me the error:
Access to XMLHttpRequest at 'localhost:3000/usuario/login' from origin 'http://IP_server' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
I don’t know what else I can do, I have tried many settings and none of them have helped me. Can you help me please? Thanks
My /etc/nginx/sites-available/default is:
server {
listen 80 default_server;
listen [::]:80 default_server;
add_header Access-Control-Allow-Origin * always;
if ($request_method = OPTIONS) {
return 200;
}
.........
root /home/ubuntu/gacibbalizas/www;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
add_header 'Access-Control-Allow-Origin' *;
}
.........