Access to XMLHttpRequest at 'https://api.krishit.com/navbar/checkforNavbar' from origin 'https://hrms.krishit.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Access to XMLHttpRequest at 'https://api.krishit.com/navbar/checkforNavbar' from origin 'https://hrms.krishit.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
nodejs was not running and thats why giving this error
pm2 start app.js from hrms folder
or
cat nginx.ssl.conf
#=========================================================================#
# Default Web Domain Template #
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
# https://hestiacp.com/docs/server-administration/web-templates.html #
#=========================================================================#
server {
listen 92.222.128.232:443 ssl;
server_name api.krishit.com www.api.krishit.com;
# Main proxy
location / {
proxy_pass http://localhost:5000;
proxy_set_header Host $host; # ProxyPreserveHost On
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https; # RequestHeader set X-Forwarded-Proto "https"
# Access-Control-Allow-Origin *
#add_header Access-Control-Allow-Origin *;
}
# WebSocket (socket.io)
location /socket.io/ {
proxy_pass http://localhost:5000/socket.io/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
}
error_log /var/log/apache2/domains/api.krishit.com.error.log error;
ssl_certificate /home/api.krishit/conf/web/api.krishit.com/ssl/api.krishit.com.pem;
ssl_certificate_key /home/api.krishit/conf/web/api.krishit.com/ssl/api.krishit.com.key;
ssl_stapling on;
ssl_stapling_verify on;
# TLS 1.3 0-RTT anti-replay
if ($anti_replay = 307) { return 307 https://$host$request_uri; }
if ($anti_replay = 425) { return 425; }
include /home/api.krishit/conf/web/api.krishit.com/nginx.hsts.conf*;
location ~ /\.(?!well-known\/|file) {
deny all;
return 404;
}
#location / {
# proxy_ssl_server_name on;
# proxy_ssl_name $host;
# proxy_pass https://92.222.128.232:8443;
#
# location ~* ^.+\.()$ {
# try_files $uri @fallback;
#
# root /home/api.krishit/web/api.krishit.com/public_html;
# access_log /var/log/apache2/domains/api.krishit.com.log combined;
# access_log /var/log/apache2/domains/api.krishit.com.bytes bytes;
#
# expires max;
# }
#}
location @fallback {
proxy_ssl_server_name on;
proxy_ssl_name $host;
proxy_pass https://92.222.128.232:8443;
}
location /error/ {
alias /home/api.krishit/web/api.krishit.com/document_errors/;
}
proxy_hide_header Upgrade;
include /home/api.krishit/conf/web/api.krishit.com/nginx.ssl.conf_*;
}
just uncomment this line,
#add_header Access-Control-Allow-Origin *;
Access to XMLHttpRequest at 'https://api.krishit.com/login' from origin 'https://hrms.krishit.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values 'https://hrms.krishit.com, *', but only one is allowed.
The error is caused because your response is sending two Access-Control-Allow-Origin headers:
One is being added by Nginx:
add_header Access-Control-Allow-Origin *;
Another is being added by your Node.js/Express application:
Access-Control-Allow-Origin: https://hrms.krishit.com
The browser rejects the response because the header becomes:
Access-Control-Allow-Origin: https://hrms.krishit.com, *
Only one value is allowed.
so i commented it for now
Comments
Post a Comment