This commit is contained in:
wood 2024-06-25 10:41:08 +08:00
parent 150a02b9ba
commit a0b71538b1
3 changed files with 10 additions and 10 deletions

4
eo.js
View File

@ -1,5 +1,5 @@
// 外部 JSON 文件的 URL // 外部 JSON 文件的 URL
const CSV_PATHS_URL = 'https://random-api.pages.dev/url.json'; const CSV_PATHS_URL = 'https://random-api-file.czl.net/url.json';
addEventListener('fetch', event => { addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request)); event.respondWith(handleRequest(event.request));
@ -43,7 +43,7 @@ async function handleRequest(request) {
} }
} else { } else {
// 如果不是 CSV 资源路径,返回 index.html 内容 // 如果不是 CSV 资源路径,返回 index.html 内容
const indexHtmlResponse = await fetch('https://random-api.pages.dev'); const indexHtmlResponse = await fetch('https://random-api-file.czl.net');
return new Response(indexHtmlResponse.body, { return new Response(indexHtmlResponse.body, {
headers: { 'Content-Type': 'text/html' }, headers: { 'Content-Type': 'text/html' },
}); });

View File

@ -2,7 +2,7 @@
<html lang="zh-cmn-Hans" class="mdui-theme-dark"> <html lang="zh-cmn-Hans" class="mdui-theme-dark">
<head> <head>
<title>随机文件api-wood</title> <title>随机文件api</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" size="32x32" href="https://cdn-r2.czl.net/2023/06/20/649168ebc2b5d.png"> <link rel="shortcut icon" size="32x32" href="https://cdn-r2.czl.net/2023/06/20/649168ebc2b5d.png">
@ -88,9 +88,9 @@
object-fit: cover; object-fit: cover;
} }
</style> </style>
<link rel="stylesheet" href="https://cdnjs.czl.net/ajax/libs/mdui/2.1.1/mdui.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mdui/2.1.1/mdui.min.css">
<script src="https://cdnjs.czl.net/ajax/libs/mdui/2.1.1/mdui.global.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/mdui/2.1.1/mdui.global.js"></script>
<script src="https://cdnjs.czl.net/ajax/libs/markdown-it/13.0.2/markdown-it.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/13.0.2/markdown-it.min.js"></script>
</head> </head>
<body class="mdui-prose"> <body class="mdui-prose">
@ -110,7 +110,7 @@
}); });
// 异步加载 index.md 文件内容 // 异步加载 index.md 文件内容
fetch('https://random-api.pages.dev/index.md') fetch('https://random-api-file.czl.net/index.md')
.then(response => response.text()) .then(response => response.text())
.then(markdownText => { .then(markdownText => {
// 渲染 Markdown 内容 // 渲染 Markdown 内容
@ -120,4 +120,4 @@
</script> </script>
</body> </body>
</html> </html>

View File

@ -4,7 +4,7 @@ const app = express();
const port = 5003; const port = 5003;
// 外部 JSON 文件的 URL // 外部 JSON 文件的 URL
const CSV_PATHS_URL = 'https://random-api.pages.dev/url.json'; const CSV_PATHS_URL = 'https://random-api-file.czl.net/url.json';
/** /**
* 处理客户端请求并根据请求的URL路径获取对应的CSV文件中的随机一行的URL然后重定向到该URL * 处理客户端请求并根据请求的URL路径获取对应的CSV文件中的随机一行的URL然后重定向到该URL
@ -51,7 +51,7 @@ async function handleRequest(req, res) {
} }
} else { } else {
// 请求路径不在配置中,返回默认首页 // 请求路径不在配置中,返回默认首页
const indexHtmlResponse = await fetch('https://random-api.pages.dev'); const indexHtmlResponse = await fetch('https://random-api-file.czl.net');
const indexHtml = await indexHtmlResponse.text(); const indexHtml = await indexHtmlResponse.text();
return res.type('html').send(indexHtml); return res.type('html').send(indexHtml);
} }