0

i am getting "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://"myurl". (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 504" here is my API

createGroup(language, req, callback) {
let data = req.body;

if(req.file){

  const csvFilePath = req.file.path;
 
  var username=
  csv()
    .fromFile(csvFilePath)
    .then((jsonObj) => {
      
      var array1 = [];
      for (let i = 0; i < jsonObj.length; i++) {

        array1.push(jsonObj[i].phoneNumber);
      }
      UserCollection.find({ mobile: { $in: array1 } }, function (err, docs) {
        if (err) {
          console.log(err)
        }
        else {
          // console.log(docs[0]._id);
          var array2 = [];
          for (let i = 0; i < docs.length; i++) {
            array2.push(docs[i]._id.toString());
          }
          

          let groupObj = new Group({
            groupName: data.groupName,
            users: array2,
            courses: [],
            effectiveDate: data.effectiveDate,
            effectiveStatus: data.effectiveStatus,
            createdBy:ObjectId(req.id)
          });
         
          groupObj.save((error, result) => {
            if (error) {
              return callback(false, common.errorMsg("Went wrong"));
            }
            return callback(false, common.successMsg("GROUP CREATED", {}));
          });
        }
      });

    }
    )
}else{
  let groupObj = new Group({
    groupName: data.groupName,
    users: data.users,  //.split(","),
    courses: [],
    effectiveDate: data.effectiveDate,
    effectiveStatus: data.effectiveStatus,
    createdBy:ObjectId(req.id)
  });
  
  groupObj.save((error, result) => {
    if (error) {
      console.log(error)
      return callback(false, common.errorMsg("Went wrong"));
    }
    return callback(false, common.successMsg("GROUP CREATED", {}));
  });
}
  

};

here is the post request i am sending from front end

groupName: testing users: 61937f894f95f04da73cc586 effectiveStatus: 1 effectiveDate: Fri Aug 19 2022 files:

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
  • 2
    504 is a gateway timeout, cors is cors. Are you sure those errors are coming (a) from the same code, and (b) this code? – Dave Newton Aug 19 '22 at 13:23
  • Could you show us more error details? – Pylon Aug 19 '22 at 13:27
  • Dave Newton yes its the same code i am working on a website i am testing same API via postman its accepts data and create the collection in DB but same code is in the server and while posting data from webpage nothings happens and also shows pending in console response header – Yogesh Kumar Aug 19 '22 at 15:00

0 Answers0