在HuggingFace上搭建Uptime kuma并接入数据库

由于Hugging Face定期清理数据,重启后面板里的东西都要重新导入,所以我们接入数据库避免这一问题。

1.创建一个aiven账号

https://aiven.io/mysql

2.创建一个MySQL数据库

image.png

image.png

记住这五项

3.在Hugging Face拉取uptime kuma镜像

https://huggingface.co/spaces/sugar404/uptime-kuma?duplicate=true

类型填mariadb
image.png
对应按编号填入,然后点击Duplicate Space

4.创建data/db-config.json文件

填入:data/db-config.json

1
2
3
4
5
6
7
8
{
"type": %(ENV_UPTIME_KUMA_DB_TYPE)s,
"host": %(ENV_UPTIME_KUMA_DB_HOSTNAME)s,
"port": %(ENV_UPTIME_KUMA_DB_PORT)s,
"user": %(ENV_UPTIME_KUMA_DB_USERNAME)s,
"password": %(ENV_UPTIME_KUMA_DB_PASSWORD)s,
"database": %(ENV_UPTIME_KUMA_DB_NAME)s
}

重启项目即可

5.进入cloudflare反代
获取我们的访问地址
image.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
exportdefault {
asyncfetch(request, env) {
const _url =new URL(request.url);
const hostname = _url.hostname;
_url.hostname = "xxx.hf.space";
const req =new Request(_url, request);
req.headers.set('origin', 'https://xxx.hf.space');

const res =await fetch(req);
let newres =new Response(res.body, res);

let location = newres.headers.get('location');
if (location !==null && location !== "") {

// 可选 - >// 去除原始路径中的 /dashboard
location = location.replace('/dashboard', '');
// 添加 /status/web 路径
location = location + '/status/web';
// <- 可选

location = location.replace('://xxx.hf.space', '://'+hostname);
newres.headers.set('location', location);
}
return newres;
},
};