Skip to content

Commit 8e7c1e1

Browse files
authored
Merge pull request #2 from sebastiendelorme/master
TypeError: Request with GET/HEAD method cannot have body
2 parents c20260b + 6dd1dd4 commit 8e7c1e1

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

functions/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,16 @@ exports.cors = functions.https.onRequest((req, res) => {
5959
}, {});
6060

6161
// Send Interpreted Request to intended endpoint:
62-
return fetch(url, {
62+
let fwdRequest = {
6363
method: req.method,
64-
body:
65-
req.get('content-type') === 'application/json'
66-
? JSON.stringify(req.body)
67-
: req.body,
68-
headers
69-
}).then(r => {
64+
headers,
65+
};
66+
if (req.method === "POST" || req.method === "PUT") {
67+
req.get("content-type") === "application/json"
68+
? (fwdRequest.body = JSON.stringify(req.body))
69+
: (fwdRequest.body = req.body);
70+
}
71+
return fetch(url, fwdRequest).then(r => {
7072
r.body.on('data', chunk => {
7173
res.write(chunk);
7274
});

0 commit comments

Comments
 (0)