Skip to content

Commit

Permalink
Update _worker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
cmliu authored Jun 12, 2024
1 parent 83acb89 commit 85918b6
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion _worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,37 @@ function isUUID(uuid) {
return uuidRegex.test(uuid);
}

async function nginx() {
const text = `
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
`
return text ;
}

export default {
async fetch(request, env, ctx) {
const getReqHeader = (key) => request.headers.get(key); // 获取请求头
Expand All @@ -76,8 +107,21 @@ export default {
pathname === '/favicon.ico',
pathname === '/auth/profile',
];

if (conditions.some(condition => condition)) {
if (env.URL302){
return Response.redirect(env.URL302, 302);
} else if (env.URL){
if (env.URL.toLowerCase() == 'nginx'){
//首页改成一个nginx伪装页
return new Response(await nginx(), {
headers: {
'Content-Type': 'text/html; charset=UTF-8',
},
});
} else return fetch(new Request(env.URL, request));
}

const newUrl = new URL("https://hub.docker.com" + pathname + url.search);

// 复制原始请求的标头
Expand Down

0 comments on commit 85918b6

Please sign in to comment.