1

Cloud function for data sync from Firebase to mysql not recognizig arabic data. error showing after sending arabic data. generated logs below

my cloud function code is below:

const functions = require('firebase-functions');
const https = require('https')

exports.myFunction = functions.firestore
  .document('distri/{docId}')
  .onWrite((change, context) => { 
    reqstatus = true;

    // console.log(change);
    //console.log(context);

    //console.log(change.after.data());

    obj = {};
    obj.id = context.params.docId;
    obj.table = 'distri';
    obj.data = change.after.data();
    data = JSON.stringify(obj);
    console.log(data);

    options = {
    hostname: 'xyz.com',
    port: 443,
    path: '/app',
    method: 'POST',
    headers: {
    'Content-Type': 'application/json; charset=UTF-8',
    'Content-Length': data.length,
    'Content-Encoding': 'utf-8'
    }
    }

  const req = https.request(options, res => {
  console.log(`statusCode: ${res.statusCode}`)

  res.on('data', d => {
  process.stdout.write(d)
  })
  })

  req.on('error', error => {
  console.error(error)
  reqstatus = false;
  })

  req.write(data)
  req.end()

  return reqstatus;

});

Api is working fine when it recieves data in english. API is based on simple php which insert data into MYSQL.

Asad Syed
  • 11
  • 1

0 Answers0