始终通过使用头盔在express.js中设置的X-Frame-Options获得拒绝加载

时间:2018-04-14 08:06:36

标签: node.js express x-frame-options

我一次又一次地得到同样的错误。我已将头盔用于X-Frame-Options,而其他标头则使用access-allow。在firefox控制台显示" X-Frame-Options拒绝加载:不允许框架。"在Chrome控制台显示"拒绝在框架中显示,因为它设置了X-Frame-Options' to' sameorigin'。" 请给我一些解决方案。任何建议将不胜感激。 这是代码:

var app = express();
var helmet = require('helmet');
app.use(helmet({
  frameguard: {
    action: 'allow-from',
    domain: 'https://calendar.google.com/calendar/'
  }
}))

var enableCORS = function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
  res.header('Access-Control-Allow-Headers', 'Content-Type, token, Content-Length, X-Requested-With, *');
  if ('OPTIONS' === req.method) {
    res.sendStatus(200);
  } else {
    next();
  }
};
app.all("/*", function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
  res.header('Access-Control-Allow-Headers', 'Content-Type, token, Content-Length, X-Requested-With, *');
  // res.set('X-Frame-Options', 'ALLOW-FROM htps://google.com/');
  next();
});
app.use(enableCORS);

1 个答案:

答案 0 :(得分:0)

您的配置恰恰相反:

X-Frame-Options

允许https://calendar.google.com/calendar/您的页面放入iframe中。 某些网站不允许其他网站构建其内容,这就是您收到错误的原因,因为如果https://calendar.google.com/calendar/DENY设置为SAMEORIGINALLOW-FROM http://example.com或{{1} } http://example.com与您的其他域名不同,您无法构建任何https://calendar.google.com/calendar/内容。

查看herehere了解更多信息。

相关问题