Help me with a project (NODEJS)

Hello! I have done extensive research and I cannot figure this out:

There are these discord middle click gifs where when you middle click on them (to open the link) it brings up this website, but the url you pasted on Discord to create the gif was clearly a link to a gif (not)

Can anyone help me with replicating this with Nodejs/html/js

Here is an example site: https://middleclick.wtf/

Here is a video of this behavior: https://youtu.be/jVM9aMo6x-8

Any help appreciated, thx

2 Likes

give me a minute I think I know how to do this but I have to test it to be sure

3 Likes

so I cant figure out how to make it work with discourse but here is an example that works on discord

code: https://replit.com/@SharkCoding/redirect

site: https://redirect.sharkcoding.repl.co/

the image is hard coded, but it shouldnt be too hard to change the way it works if you look at the code

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.

Opened since devepation wanted to reply

3 Likes

Would have to find a header or something that discourse doesn’t provide when fetching contents of a page. Could also be because Discourse doesnt convert URLs into images, but yeah. Works! How did you figure this out? :eyes:

1 Like

Well, the main part is to detect whether the link is being requested from the browser or from discord, and I came up with a slightly sketchy solution, but it works.

if (req.headers["sec-fetch-dest"]) {
    // do a redirect
} else {
    // send the image
}

The sec-fetch-dest header appears when the browser makes a request, but not when discord makes a request, so this way you can differentiate between them. Then all you have to do is either redirect to the page, or send the image.

2 Likes

I saw that in the code, but how did you figure that out

Well what I did was I created a function that literally just logged the headers when a request was made. Then, I opened the link on the browser and again in discord. I was able to look at each of the headers for the two requests and find the differences between them, and how to tell them apart.

1 Like

nice!

Can I close this now?

finee

K solution has been given so closed