4
votes

I am trying to get my head around using GCF and Express together. All of the examples I have found give good info about Firebase CF but not straight up GCF.

Specifically, I need to use body-parser to get at some POSTed body info that is being sent via a content-type of 'x-www-form-urlencoded' rather than 'application/json'. I can see the data if I console.log the req.rawBody but haven't found a clean way to get at the body parts.

I found this article: https://mhaligowski.github.io/blog/2017/05/15/serving-functions-express.html but to me it is just a couple of code snippets that really isn't clear on how things actually hang together.

1
Here [github.com/expressjs/body-parser#bodyparserurlencodedoptions] you can find some examples of express body-parser that may be helpful for your case - gr7

1 Answers

0
votes

You can require body-parser and as long as you send the Content-Type: application/json header, it will parse as JSON automatically:

const bodyParser = require('body-parser');

exports.acceptJson = (req, res) => {
    console.log(req.body);
    res.status(200);
};