Function seeing axios.post as GET request

Hey there,

I started seeing issues with my function not working and I think I’ve narrowed down the issue to how my function is receiving my request once I POST to it.

Netlify function
Github: https://github.com/colbyfayock/tweet
Site: https://tweet-with-twitter.netlify.app/

Code calling function
Github: https://github.com/colbyfayock/amazon-goldbox/blob/master/rss.js#L116
Snippet:

    await axios.post('https://tweet-with-twitter.netlify.com/.netlify/functions/tweet', payload, {
      headers: {
        Authorization: token
      }
    });

When running this locally, there doesn’t seem to be any problems with my payload, it fires and returns a 200. However, when POSTing the exact same code to the deploy function, the body appears to be empty. I confirmed this with logs to debug the function.

To debug that, I console.log’ed the event itself, and it turns out on Netlify, my function is receiving that POST as a GET:

    INFO	event {
      path: '/.netlify/functions/tweet',
      httpMethod: 'GET',
      headers: {

Locally:

    Request from ::ffff:127.0.0.1: POST /tweet

Any thoughts about what’s going on here? I was originally running the function on node v8, but I updated the .nvmrc to v12 and tested locally with the same version (in both instances). Still the same issue.

Thanks

Hi @colbyfayock, I tried invoking your function using insomnia and if you check your function logs, it does show the httpMethod as POST. Could you try using the object method like below?

axios({
  method: 'post',
  url: 'http://bit.ly/2mTM3nY',
  data: <body here>
}) 

Let me know if that works.

I tried updating to that format and testing locally and still only seem to get a GET which is bizarre…

await axios({
  method: 'post',
  url: 'https://tweet-with-twitter.netlify.com/.netlify/functions/tweet',
  data: payload,
  headers: {
    'Authorization': token
  }
});

I did however try to POST with fetch just to test and it seems to go through as a POST but just having trouble getting the formatting to take in the payload right :thinking: so maybe it’s an issue between axios and the serverless framework which i’m using for the app?

The strange thing is that it works on my locally served netlify function (localhost:9000) but not when posting directly there.

await axios({
  method: 'post',
  url: 'http://localhost:9000/tweet',
  // url: 'https://tweet-with-twitter.netlify.com/.netlify/functions/tweet',
  data: JSON.stringify(payload),
  headers: {
    'Authorization': token
  }
});

Anyways, I’ll either use a different tool or keep digging.

Thanks