Access to XMLHttpRequest at 'https://smstest-gevxguoisq-ew.a.run.app/test' from origin 'null' has been blocked by CORS policy: code example

Example 1: javascript access to xmlhttprequest at from origin 'null' has been blocked by cors policy

//Open the HTML file using live server, it will work

Example 2: Access to XMLHttpRequest has been blocked by CORS policy

/*
npm i cors
or
 yarn add cors
then in your node app
*/
const cors = require('cors');
const corsOptions ={
    origin:'http://localhost:3000', 
    credentials:true,            //access-control-allow-credentials:true
    optionSuccessStatus:200
}
app.use(cors(corsOptions));

Tags:

Misc Example