V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
huolong
V2EX  ›  问与答

关于 CF workers 反代后的网站无法内嵌问题

  •  
  •   huolong · 7 天前 · 209 次点击

    请问各位大佬。我用 CF 的 worker 反代了 google 的学术镜像站。现在有个问题是当吧镜像站内嵌在网站的某个页面里时候,发现打不开网站。浏览器抓包提示的是因为是 (‘X-Frame-Options’); 是 sameOrigin 导致,应该就是不允许跨域问题,这种情况下该怎么能让这个镜像站内嵌呢。 我根据 GPT 的提示,在请求的时候删除掉 这个 X-FRAME-OPTIONS ,发现并无什么卵用。代码如下,请问各位大佬如何实现内嵌呢?

    ` export default { async fetch(request, env) { const _url = new URL(request.url); const hostname = _url.hostname; _url.hostname = "scholar.google.com";

    const req = new Request(_url, request);
    req.headers.set('Referer', 'https://scholar.google.com/');
    req.headers.set('Origin', 'https://scholar.google.com/');
    req.headers.delete('X-Frame-Options');
    
    const res = await fetch(req);
    const newRes = new Response(res.body, res);
    
    newRes.headers.set('Access-Control-Allow-Origin', '*');
    newRes.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
    newRes.headers.set('Access-Control-Allow-Headers', 'Content-Type');
    
    let location = newRes.headers.get('location');
    if (location !== null && location !== "") {
      location = location.replace('://scholar.google.com/', '://' + hostname);
      newRes.headers.set('location', location);
    }
    
    return newRes;
    

    }, };

    `

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1003 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 22:59 · PVG 06:59 · LAX 15:59 · JFK 18:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.