-1

i have code axios :

  var url =`laporan_type=${typeLaporan}&provinsi_id=${id_provinsi}&id_kabkota=${id_kabkota}&id_kecamatan=${id_kecamatan}&year=${year}&month=${month}`
  axios({
    method: 'get',
    url: `${simkah}/laporan/reportWord?${url}`,
    headers: {
      'Access-Control-Allow-Origin': '*',
      'Content-Type': 'application/json',
    },
    responseType: "blob"
  }).then(
    (response) => {
      const url = window.URL.createObjectURL(new Blob([response.data]));
      const link = document.createElement('a');
      link.href = url;
      link.setAttribute('download', filename);
      document.body.appendChild(link);
      link.click();
    }
  ).catch((error) => { 
    console.log(error);
  });

and i get error CORS. Can you help me pls ( i have seen many topic and i still don't understand why it is not working

kissu
  • 40,416
  • 14
  • 65
  • 133
alv
  • 7
  • 5
  • CORS are to be set on the backend, not the frontend: https://stackoverflow.com/a/72211930/8816585 – kissu Sep 05 '22 at 11:58

1 Answers1

0

CORS is to be set on the backend, Ask your backend laravel developer to create a CORS middleware and pass that in API routes. So whenever you send the request from API just send all the headers you'll get a successful response. To create middleware in laravel just followed any suitable tutorials or create it on your own. Middleware tutorial: https://www.stackhawk.com/blog/laravel-cors/