Accessing the website url via watspps message, the screen is not navigating and throws cors error

While accessing the website url from Wats App message in mobile and laptop, I am getting below error.

Access to XMLHttpRequest at ‘https://www.my_domain.com.au/service/teamTokenGenerator’ from origin ‘https://my_domain.com.au’ 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.Understand this error TeamTokenGenerator.js:56

But accessing the site normally from browser www.my_domain.com.au, I don’t get any issue. Ít works fine, could someone please advise how can I fix the problem ?

//server.js

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> const express = require('express');
const bodyParser = require("body-parser");
const cors = require('cors');
const app = express();
app.use(cors({
origin: ['https://www.my_domain.com.au'],
methods: 'GET,POST,PUT,DELETE',
credentials: true
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
(async () => {
try {
const sequelizeStatus = await sequelize.sync();
console.log("your server is up and running");
app.listen(port, () => console.log(`Listening on port ${port}`));
} catch (e) {
console.log(e, 'Database issue.');
}
})();
</code>
<code> const express = require('express'); const bodyParser = require("body-parser"); const cors = require('cors'); const app = express(); app.use(cors({ origin: ['https://www.my_domain.com.au'], methods: 'GET,POST,PUT,DELETE', credentials: true })); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); (async () => { try { const sequelizeStatus = await sequelize.sync(); console.log("your server is up and running"); app.listen(port, () => console.log(`Listening on port ${port}`)); } catch (e) { console.log(e, 'Database issue.'); } })(); </code>
    const express = require('express');
    const bodyParser = require("body-parser");
    const cors = require('cors');
    
    
    const app = express();
    
    app.use(cors({
      origin: ['https://www.my_domain.com.au'], 
      methods: 'GET,POST,PUT,DELETE',
      credentials: true
    }));
    
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    
(async () => {
  try {
    const sequelizeStatus = await sequelize.sync();
    console.log("your server is up and running");
    app.listen(port, () => console.log(`Listening on port ${port}`));
  } catch (e) {
    console.log(e, 'Database issue.');
  }
})();

nginx configuration:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>server {
listen 80;
server_name my_domain.com.au www.my_domain.com.au;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name my_domain.com.au www.my_domain.com.au;
ssl_certificate /var/www/ssl/certificate.crt;
ssl_certificate_key /var/www/ssl/my_domain.com.key;
##ssl_trusted_certificate /var/www/ssl/ca_bundle.crt
root /var/www/my_domain.com.au/build;
index index.html;
##Other SSL settings
location / {
try_files $uri $uri/ /index.html;
}
##Optionally, handle specific requests such as favicon.ico
location /favicon.ico {
try_files $uri =404;
}
##This will handle static files under `/static/` directory
location /static/ {
try_files $uri $uri/ =404;
}
location /images/ {
alias /root/my_domain/public/images/;
}
location /service {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
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 $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
##CORS headers
add_header 'Access-Control-Allow-Origin' 'https://www.my_domain.com.au';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
}
</code>
<code>server { listen 80; server_name my_domain.com.au www.my_domain.com.au; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name my_domain.com.au www.my_domain.com.au; ssl_certificate /var/www/ssl/certificate.crt; ssl_certificate_key /var/www/ssl/my_domain.com.key; ##ssl_trusted_certificate /var/www/ssl/ca_bundle.crt root /var/www/my_domain.com.au/build; index index.html; ##Other SSL settings location / { try_files $uri $uri/ /index.html; } ##Optionally, handle specific requests such as favicon.ico location /favicon.ico { try_files $uri =404; } ##This will handle static files under `/static/` directory location /static/ { try_files $uri $uri/ =404; } location /images/ { alias /root/my_domain/public/images/; } location /service { proxy_pass http://localhost:8000; proxy_set_header Host $host; 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 $scheme; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_http_version 1.1; proxy_cache_bypass $http_upgrade; ##CORS headers add_header 'Access-Control-Allow-Origin' 'https://www.my_domain.com.au'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type'; if ($request_method = 'OPTIONS') { add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain charset=UTF-8'; add_header 'Content-Length' 0; return 204; } } } </code>
server {
    listen 80;
    server_name my_domain.com.au www.my_domain.com.au;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name my_domain.com.au www.my_domain.com.au;

    ssl_certificate /var/www/ssl/certificate.crt;
    ssl_certificate_key /var/www/ssl/my_domain.com.key;
    ##ssl_trusted_certificate /var/www/ssl/ca_bundle.crt

    root /var/www/my_domain.com.au/build;
    index index.html;

    ##Other SSL settings

    location / {
        try_files $uri $uri/ /index.html;
    }

    ##Optionally, handle specific requests such as favicon.ico

    location /favicon.ico {
        try_files $uri =404;
    }

    ##This will handle static files under `/static/` directory

    location /static/ {
        try_files $uri $uri/ =404;
    }

    location /images/ {
       alias /root/my_domain/public/images/;
    }
    
     location /service {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
        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 $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_http_version 1.1;
        proxy_cache_bypass $http_upgrade;

        ##CORS headers
        add_header 'Access-Control-Allow-Origin' 'https://www.my_domain.com.au';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';

        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 204;
        }
    }


}

Client side code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>const onSubmit = async (data) => {
const name = data.name;
const mobileNumber = data.mobileNumber;
setMobileNumber(mobileNumber);
try {
const response = await axios.post(`${appUrl}/service/teamTokenGenerator`, { name, mobile: mobileNumber });
const generatedToken = response.data.token;
setToken(generatedToken);
setTokenAvailable(true);
} catch (err) {
setError("Failed to generate token. Please try again.");
}
};
REACT_APP_URL='https://www.my_domain.com.au'
"proxy": "https://www.my_domain.com.au", // in package.json
</code>
<code>const onSubmit = async (data) => { const name = data.name; const mobileNumber = data.mobileNumber; setMobileNumber(mobileNumber); try { const response = await axios.post(`${appUrl}/service/teamTokenGenerator`, { name, mobile: mobileNumber }); const generatedToken = response.data.token; setToken(generatedToken); setTokenAvailable(true); } catch (err) { setError("Failed to generate token. Please try again."); } }; REACT_APP_URL='https://www.my_domain.com.au' "proxy": "https://www.my_domain.com.au", // in package.json </code>
const onSubmit = async (data) => {

        const name = data.name;
        const mobileNumber = data.mobileNumber;
        setMobileNumber(mobileNumber);

        try {
            const response = await axios.post(`${appUrl}/service/teamTokenGenerator`, { name, mobile: mobileNumber });
            const generatedToken = response.data.token;
            setToken(generatedToken);
            setTokenAvailable(true);
        } catch (err) {
            setError("Failed to generate token. Please try again.");
        }
    };


REACT_APP_URL='https://www.my_domain.com.au'

"proxy": "https://www.my_domain.com.au",   // in package.json 

Getting below error;

Access to XMLHttpRequest at ‘https://www.my_domain.com.au/service/teamTokenGenerator’ from origin ‘https://my_domain.com.au’ 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.Understand this error
TeamTokenGenerator.js:56

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật