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
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?
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.
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.