【问题标题】:express.js res.redirect with maskingexpress.js res.redirect 带屏蔽
【发布时间】:2013-06-24 00:50:28
【问题描述】:

在 express.js 中,我可以在执行屏蔽时使用res.redirect

例如,我的应用位于http://example.com。我希望http://example.com/test 重定向到http://google.com,同时将URL 保持为http://example.com/test

换句话说,用户在 URL == http://example.com/test 时看到了 google 的着陆页。

【问题讨论】:

  • 即使在用户进行搜索或点击页面上的链接后,您是否希望 google url 被屏蔽?
  • 没有。只有他第一次上车。

标签: node.js express url-masking


【解决方案1】:

然后您可以做的是获取 Google 的 HTML 代码并将其发送到您的响应中,如下所示:

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);
};

由于这是来自 CoffeeScript 的自动翻译,因此可能需要完善一些东西,但想法就在那里。

【讨论】:

  • 唯一的问题是您需要检查损坏的链接等等。如果他们所有的链接都是绝对的而不是相对的,那么我认为这是一个非常可行的解决方案。
  • 所以我的想法是我得到谷歌的 html,并在我的页面上呈现它。如果 google.com 页面包含 js,例如骨干应用,会发生什么?
  • 我们谈论的是 google.com,而不是 gmail.com。那将是一个完全不同的解决方案。
猜你喜欢
  • 2016-06-13
  • 1970-01-01
  • 2022-06-28
  • 2018-05-08
  • 1970-01-01
  • 2014-07-20
  • 2012-09-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多