Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用cloudflare workers呈现html页面_Javascript_Html_Cloudflare_Worker - Fatal编程技术网

Javascript 如何使用cloudflare workers呈现html页面

Javascript 如何使用cloudflare workers呈现html页面,javascript,html,cloudflare,worker,Javascript,Html,Cloudflare,Worker,我已经创建了一个路由,当我使用它时,它将呈现所需的页面,但当我添加?否则它将给出错误1000 DNS指向要在不想使用的给定路由中实现的禁止IP * . 这是我的密码 const html1 = `<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport"

我已经创建了一个路由,当我使用它时,它将呈现所需的页面,但当我添加?否则它将给出错误1000 DNS指向要在不想使用的给定路由中实现的禁止IP * . 这是我的密码

const html1 = `<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css"
      rel="stylesheet"
    />
    <script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
    <link
      rel="stylesheet"
      href="https://fonts.googleapis.com/icon?family=Material+Icons"
    />
    <style>
      .button {
        background-color: rgba(162, 51, 79, 0.3);
        text-decoration: none;
        color: #a2334f;
        width: 150px;
        border: none;
        padding: 13px 26px;
        text-align: center;
        display: inline-block;
        font-weight: 600;
        font-size: 16px;
        line-height: 19px;
        margin: 4px 2px;
        cursor: pointer;
        opacity: 0.7;
        border-radius: 5px;
      }
    </style>
  </head>
  <body>
    <a href="" class="button"> Know More </a>
  </body>
</html>
`


const html2 = `<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css"
      rel="stylesheet"
    />
    <script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
    <link
      rel="stylesheet"
      href="https://fonts.googleapis.com/icon?family=Material+Icons"
    />
    <style>
      .button {
        background-color: rgba(162, 51, 79, 0.3);
        text-decoration: none;
        color: #a2334f;
        width: 150px;
        border: none;
        padding: 13px 26px;
        text-align: center;
        display: inline-block;
        font-weight: 600;
        font-size: 16px;
        line-height: 19px;
        margin: 4px 2px;
        cursor: pointer;
        opacity: 0.7;
        border-radius: 5px;
      }
    </style>
  </head>
  <body>
    <a href="" class="button"> Know More </a>

    <p>queryy</p>
  </body>
</html>
`
addEventListener('fetch', (event) => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
 console.log(request.url)
 console.log(request.url.includes('/?'))

  if(request.url==='https://bewithrits.tech' ||request.url==='https://bewithrits.tech/'){
 return new Response(html1, {
      headers: {
        'content-type': 'text/html;charset=UTF-8',
        'Access-Control-Allow-Origin': 'https://bewithrits.tech',
        'Access-Control-Allow-Methods': 'OPTIONS, HEAD, POST, GET',
        'Access-Control-Allow-Headers':
          'X-Requested-With, Authorization,' + 'Content-Type, Accept',
      },
    })

  }
  
  else if(request.url.includes('/?')){
     return new Response(html2, {
      headers: {
        'content-type': 'text/html;charset=UTF-8',
        'Access-Control-Allow-Origin': 'https://bewithrits.tech',
        'Access-Control-Allow-Methods': 'OPTIONS, HEAD, POST, GET',
        'Access-Control-Allow-Headers':
          'X-Requested-With, Authorization,' + 'Content-Type, Accept',
      },
    })
  }
}
const html1=`
文件
.按钮{
背景色:rgba(162,51,79,0.3);
文字装饰:无;
颜色:#a2334f;
宽度:150px;
边界:无;
填充:13px26px;
文本对齐:居中;
显示:内联块;
字号:600;
字体大小:16px;
线高:19px;
利润:4倍2倍;
光标:指针;
不透明度:0.7;
边界半径:5px;
}
`
常量html2=`
文件
.按钮{
背景色:rgba(162,51,79,0.3);
文字装饰:无;
颜色:#a2334f;
宽度:150px;
边界:无;
填充:13px26px;
文本对齐:居中;
显示:内联块;
字号:600;
字体大小:16px;
线高:19px;
利润:4倍2倍;
光标:指针;
不透明度:0.7;
边界半径:5px;
}
克瑞

` addEventListener('fetch',(事件)=>{ event.respondWith(handleRequest(event.request)) }) 异步函数handleRequest(请求){ console.log(request.url) console.log(request.url.includes('/?')) if(request.url=='https://bewithrits.tech“||请求.url==”https://bewithrits.tech/'){ 返回新响应(html1{ 标题:{ “内容类型”:“text/html;charset=UTF-8”, “访问控制允许来源”:https://bewithrits.tech', “访问控制允许方法”:“选项、标题、帖子、获取”, “访问控制允许标头”: “X-Requested-With,Authorization,”+“内容类型,Accept”, }, }) } else if(request.url.includes('/?')){ 返回新响应(html2{ 标题:{ “内容类型”:“text/html;charset=UTF-8”, “访问控制允许来源”:https://bewithrits.tech', “访问控制允许方法”:“选项、标题、帖子、获取”, “访问控制允许标头”: “X-Requested-With,Authorization,”+“内容类型,Accept”, }, }) } }
您需要使用web服务器IP地址作为A记录。您正在将A记录指向Cloudflare的服务器,但不应这样做


如果要将URL与查询参数(其中包含
的URL)匹配,则需要尾部的
*
。不幸的是,这是无法避免的

这是目前解释Cloudflare Workers路由模式的方式中的一个已知问题。我们想改变它,但这很棘手,因为我们不想破坏任何依赖现有行为的现有员工