Reputation: 4448
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
.
Upvotes: 1
Views: 2523
Reputation: 3486
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.
Upvotes: 1