1

In express.js, can I use res.redirect while performing masking.

Example, my app is at http://example.com. I want http://example.com/test to redirect to http://google.com while keeping the URL as http://example.com/test.

In other words, the user sees google's landing-page while URL == http://example.com/test.

JRulle
  • 7,448
  • 6
  • 39
  • 61
tUrG0n
  • 4,178
  • 3
  • 20
  • 26

1 Answers1

1

What you can do then is to get the Google's HTML code and send it in your response like this :

var request = require('request'); // https://github.com/mikeal/request

function (html) {
  return request.get('http://www.google.com', (error, response, body) => {
    if (!error && response.statusCode === 200) {
      return body;
    }
  });
  res.set('Content-Type', 'text/html');
  res.send(html);
};

Since this is a automated translation from CoffeeScript, things might need to be polished, but the idea is there.

Wong Jia Hau
  • 2,639
  • 2
  • 18
  • 30
brnrd
  • 3,396
  • 3
  • 31
  • 41
  • the only problem with this is that you need to check for broken links and whatnot. if all of their links are absolute and not relative, then i think this is a very viable solution. – gr3co Sep 03 '13 at 16:34
  • So the idea is that i get google's html, and render it on my page. What would happen if the google.com page contains js, for instance, a backbone app? – tUrG0n Sep 04 '13 at 08:23
  • We are talking about google.com, not gmail.com. That would be a completely other solution. – brnrd Sep 04 '13 at 10:26