Skip to content

Commit d046044

Browse files
committed
feat: help html
1 parent dfac79d commit d046044

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

src/help.html

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-CN">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>镜像使用说明</title>
7+
<style>
8+
body {
9+
font-family: 'Roboto', sans-serif;
10+
margin: 0;
11+
padding: 0;
12+
background-color: #f4f4f4;
13+
}
14+
.header {
15+
background: linear-gradient(135deg, #667eea, #764ba2);
16+
color: #fff;
17+
padding: 20px 0;
18+
text-align: center;
19+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
20+
position: relative;
21+
}
22+
.github-link {
23+
position: absolute;
24+
top: 10px;
25+
right: 20px;
26+
color: #fff;
27+
text-decoration: none;
28+
}
29+
.github-icon {
30+
width: 24px;
31+
height: 24px;
32+
vertical-align: middle;
33+
}
34+
.container {
35+
max-width: 800px;
36+
margin: 40px auto;
37+
padding: 20px;
38+
background-color: #fff;
39+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
40+
border-radius: 10px;
41+
}
42+
.content {
43+
margin-bottom: 20px;
44+
}
45+
.footer {
46+
text-align: center;
47+
padding: 20px 0;
48+
background-color: #333;
49+
color: #fff;
50+
}
51+
pre {
52+
background-color: #272822;
53+
color: #f8f8f2;
54+
padding: 15px;
55+
border-radius: 5px;
56+
overflow-x: auto;
57+
}
58+
code {
59+
font-family: 'Source Code Pro', monospace;
60+
}
61+
a {
62+
color: #4CAF50;
63+
text-decoration: none;
64+
}
65+
a:hover {
66+
text-decoration: underline;
67+
}
68+
@media (max-width: 600px) {
69+
.container {
70+
margin: 20px;
71+
padding: 15px;
72+
}
73+
.header {
74+
padding: 15px 0;
75+
}
76+
}
77+
</style>
78+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Source+Code+Pro:wght@400;700&display=swap" rel="stylesheet">
79+
</head>
80+
<body>
81+
<div class="header">
82+
<h1>镜像使用说明</h1>
83+
<a href="https://github.com/lixd/cloudflare-docker-proxy" target="_blank" class="github-link">
84+
<img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" alt="GitHub" class="github-icon">
85+
</a>
86+
</div>
87+
<div class="container">
88+
<div class="content">
89+
<p>为了加速 Docker 镜像拉取,你可以使用以下命令设置 registry mirror:</p>
90+
<pre><code id="registry-config">sudo tee /etc/docker/daemon.json &lt;&lt;EOF
91+
{
92+
"registry-mirrors": ["https://{{host}}"]
93+
}
94+
EOF
95+
# 配置完后需要重启 Docker 服务
96+
sudo systemctl restart docker
97+
</code></pre>
98+
<p>使用该代理从不同的镜像仓库拉取镜像,请参考以下命令:</p>
99+
<pre><code id="commands">
100+
# docker pull nginx:latest
101+
docker pull docker.{{host}}/library/nginx:latest # 拉取 Docker 官方镜像
102+
103+
# docker pull quay.io/coreos/etcd:latest
104+
docker pull quay.{{host}}/coreos/etcd:latest # 拉取 Quay 镜像
105+
106+
# docker pull gcr.io/google-containers/busybox:latest
107+
docker pull gcr.{{host}}/google-containers/busybox:latest # 拉取 GCR 镜像
108+
109+
# docker pull k8s.gcr.io/pause:latest
110+
docker pull k8s-gcr.{{host}}/pause:latest # 拉取 k8s.gcr.io 镜像
111+
112+
# docker pull registry.k8s.io/pause:latest
113+
docker pull k8s.{{host}}/pause:latest # 拉取 registry.k8s.io 镜像
114+
115+
# docker pull ghcr.io/github/super-linter:latest
116+
docker pull ghcr.{{host}}/github/super-linter:latest # 拉取 GitHub 容器镜像
117+
118+
# docker pull docker.cloudsmith.io/public/repo/image:latest
119+
docker pull cloudsmith.{{host}}/public/repo/image:latest # 拉取 Cloudsmith 镜像
120+
</code></pre>
121+
<p>为了避免 Worker 用量耗尽,你可以手动 pull 镜像然后 re-tag 之后 push 至本地镜像仓库。</p>
122+
</div>
123+
</div>
124+
<div class="footer">
125+
<p>Powered by Cloudflare Workers</p>
126+
<!-- <p><a href="https://lixueduan.com" target="_blank">访问博客 探索云原生</a></p> -->
127+
</div>
128+
<script>
129+
document.addEventListener('DOMContentLoaded', function() {
130+
const host = window.location.hostname;
131+
const mainDomain = host.split('.').slice(-2).join('.');
132+
const registryConfigElement = document.getElementById('registry-config');
133+
const commandsElement = document.getElementById('commands');
134+
135+
registryConfigElement.innerHTML = registryConfigElement.innerHTML.replace(/{{host}}/g, host);
136+
commandsElement.innerHTML = commandsElement.innerHTML.replace(/{{host}}/g, mainDomain);
137+
});
138+
</script>
139+
</body>
140+
</html>

src/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import DOCS from './help.html'
2+
13
addEventListener("fetch", (event) => {
24
event.passThroughOnException();
35
event.respondWith(handleRequest(event.request));
@@ -42,6 +44,15 @@ async function handleRequest(request) {
4244
status: 404,
4345
}
4446
);
47+
}
48+
// return docs
49+
if (url.pathname === "/") {
50+
return new Response(DOCS, {
51+
status: 200,
52+
headers: {
53+
"content-type": "text/html"
54+
}
55+
});
4556
}
4657
const isDockerHub = upstream == dockerHub;
4758
const authorization = request.headers.get("Authorization");

0 commit comments

Comments
 (0)