javascriptnode.jsmeteorpickerwebapp2

Data is received at local environment but not in production in meteor js webapp


WebApp.connectHandlers.use('/hello', async (req, res, next) => {
    let data = '';
    await req.on('data', (chunk) => {
        data += chunk;
    });
    console.log("data : ", data)
    const xml_string = '<?xml version="1.0"?><cXML></cXML>`'
    res.writeHead(200, { 'Content-Type': 'text/xml' });
    res.end(xml_string);
})

I am using this method to get data. I am getting data as expected in the local environment. But after deployment, req.on('data') is not invoking and data is blank for the specific API. Another API is working on both production and local environments with the same code. I am send XML data in the request


Solution

  • Fixed this issue by following code.

    Picker.route("/hello", async (params, req, res) => {
    let data = ''
    req.on('data', Meteor.bindEnvironment((chunk) => {
        data += chunk;
    })).on('end', function() {
        console.log("data : ", data)
        const xml_string = '<?xml version="1.0"?><cXML></cXML>`'
        res.writeHead(200, { 'Content-Type': 'text/xml' });
        res.end(xml_string);
    }