【发布时间】:2020-10-21 09:49:28
【问题描述】:
我创建了一个路由https://bewithrits.tech,当我使用https://bewithrits.tech/ 时,它将呈现所需的页面,但是当我添加https://bewithrits.tech/ 时?或https://bewithrits.tech/?fb 那么它会给出错误Error 1000 DNS 指向要在给定路由中实施的禁止 IP,不想使用 https://bewithrits.tech/* 。 这是我尝试过的代码
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',
},
})
}
}
【问题讨论】:
标签: javascript html cloudflare worker