remy/wm

POST to webapp reports wrong endpoints (GET does it right)

petergoes opened this issue · 2 comments

Hi,

I have created a note on my site which I want to post to twitter with webmention.app and the webmention endpoints of brid.gy. The behaviour between a GET and a POST request to https://webmention.app/check seems different:

The GET Request
When I perform this GET request:
https://webmention.app/check?token=<MY_TOKEN>&url=https://petergoes.nl/notes/2021-05-31-20-18/
I get this response:

{
   "urls": [
     {
       "endpoint": {
         "url": "https://brid.gy/publish/webmention",
         "type": "webmention"
       },
       "source": "https://www.petergoes.nl/notes/2021-05-31-20-18/",
       "target": "https://brid.gy/publish/mastodon"
     },
     {
       "endpoint": {
         "url": "https://brid.gy/publish/webmention",
         "type": "webmention"
       },
       "source": "https://www.petergoes.nl/notes/2021-05-31-20-18/",
       "target": "https://brid.gy/publish/twitter"
     }
   ]
}

The POST Request
When I perform this POST request:
https://webmention.app/check?token=<MY_TOKEN>&url=https://petergoes.nl/notes/2021-05-31-20-18/
I get this response:

{
  "urls": [
    {
      "status": 201,
      "error": null,
      "source": "https://brid.gy/publish/mastodon",
      "target": "https://brid.gy/publish/webmention"
    },
    {
      "status": 201,
      "error": null,
      "source": "https://brid.gy/publish/twitter",
      "target": "https://brid.gy/publish/webmention"
    }
  ]
}

As with the GET request, I expected the POST request to have a target of https://brid.gy/publish/twitter, and not https://brid.gy/publish/webmention.

The status code in the POST requests are 201. So the post IS being posted to Twitter. So functionally it works.

The reason I am asking is that brid.gy is supposed to return the created tweet object when the target is https://brid.gy/publish/twitter. That Tweet object contains the created Tweet ID I need to create a rel="syndication" link back in the original post.

Other relevant things

  • This code runs as a Netlify build plugin.
  • When I use the cli (with--send), the source and target are correct, but it only states source, target and endpoint (with their values), not the response from the endpoint

I am really not sure where things go wrong. Maybe I should even ask @snarfed if it goes wrong on brid.gy?

I searched through the code to see if I could find it myself, but no luck so far.

Ah!! This is a Nuxt project! Now it makes a little more sense to me.

Here is what I found:
In lib/send/webmention.js the actual webmention is being send. And a reply back to the user is being constructed:

const reply = {
status: res.status,
error,
source: target, // this is confusing, but works in the output
target: res.url,
};

But as line 23 states, the target and source get swapped in te reply. That is what tripped me up. But explains why it functionally did what is supposed to do.

The only thing I would like now, is to have the response from the endpoint reflected in the reply. Because that probably contains the tweet object (in my case).

I hope you are open to a PR.
I will propose something right away

I have played around with the idea a bit further. I realise it adds a significant amount of code to support my use case. I don't think it is wise to add that to this project. So I'll close this issue.

If anyone stumbles upon this, I am happy to give some directions to implement it yourself