Search code examples
node.jsexpressdata-uri

How to use res.redirect to redirect to a data url?


I need to use the res.redirect() to redirect to a data URL using express.

This is my code...

app.get("/",(req,res)=>{
    res.redirect("data:text/plain;base64,hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
})

When I use another URL eg: https://www.google.com It works fine.

But when I use a data URL it is not working..

How should I fix it?

I am new to programming and StackOverflow. So, please be kind to me


Solution

  • You could redirect the user to a blob of the dataurl location.

    For that just search google for dataurl to blob in js etc.

    And also as you are using nodejs you could use the http.request and pipe the response to client just like proxying.

    or you could fetch that file with "http.request" and save it in your server and give it when the client needs it