0

while requesting data from server using Axios.post("http://localhost:5000/api/admin/getdblogo") from another device in same network , it gives the follwing error:-

Google chrome error

xhr.js:220 POST http://localhost:5000/api/admin/getdblogo net::ERR_CONNECTION_REFUSED

Morzilla firefox error

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:5000/api/admin/getdblogo. (Reason: CORS request did not succeed). Status code: (null).

what have been tried out:

in the server this line is added:

const cors = require('cors');
app.use(cors({origin:'http://localhost:3000'}));

in the client side the request that is causing the error is :

const [Logo,setLogo] = useState(null);
const GetLogo = async() => {

    const response = await Axios.post("http://localhost:5000/api/admin/getdblogo");

    if (response.data.recordset.length === 0) {

        setLogo(null);

    }
    else if (response.data.recordset.length === 1) {
        console.log(response);
        const imagedata = await btoa(String.fromCharCode(...new Uint8Array(response.data.recordset[0].PICTURE.data)));

        setLogo(imagedata);

    }

}
sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
jd singh
  • 19
  • 3

0 Answers0