I am trying to set up a cloud function that returns an xml. I am able to create and log the xml, but it crashes with the following error when I try to return it.
TypeError: Converting circular structure to JSON at Object.stringify (native) at stringify (/var/tmp/worker/node_modules/express/lib/response.js:1119:12) at ServerResponse.json (/var/tmp/worker/node_modules/express/lib/response.js:260:14) at ServerResponse.send (/var/tmp/worker/node_modules/express/lib/response.js:158:21) at cors (/user_code/index.js:663:21) at cors (/user_code/node_modules/cors/lib/index.js:188:7) at /user_code/node_modules/cors/lib/index.js:224:17 at originCallback (/user_code/node_modules/cors/lib/index.js:214:15) at /user_code/node_modules/cors/lib/index.js:219:13 at optionsCallback (/user_code/node_modules/cors/lib/index.js:199:9)
My Function
exports.sendXMLResponeSample = functions.https.onRequest((request, response) => {
cors(request, response, () => {
// import xmlbuilder
const builder = require('xmlbuilder');
// create my object to convert to xml
var myFeedObject = {
"somekey": "some value",
"age": 59,
"eye color": "brown"
}
// convert myFeedObject to xml
const feed = builder.create(myFeedObject, { encoding: 'utf-8' })
console.log("feed.end({ pretty: true }) = (below)");
console.log(feed.end({ pretty: true }));
// return xml
return response.send(200, feed) // <<< error occurs here
})
})
I believe the error suggests the the firebase cloud function is expecting I return a JSON object in the response rather than an xml object, but I am unsure how to tell it to expect an xml object in the response.
Does anyone understand how to return an xml object in a firebase cloud function?
EDIT: The object is converted to an xml object without any issue. The error occurs when the xml object is attempted to be returned.