nodejs版本部署的方式,合并到一起,不需要部署两个站点了

This commit is contained in:
wood 2024-07-28 04:28:14 +08:00
parent af1a9472b6
commit d1d21d1d05
16 changed files with 32 additions and 28 deletions

View File

@ -33,20 +33,20 @@ jobs:
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
# 解压文件
unzip -o /tmp/deployment.zip -d /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index2
unzip -o /tmp/deployment.zip -d /opt/1panel/apps/openresty/openresty/www/sites/random-api.czl.net/index2
# 删除 index 目录下的所有文件
rm -rf /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index/*
rm -rf /opt/1panel/apps/openresty/openresty/www/sites/random-api.czl.net/index/*
# 移动文件,采用覆盖模式
mv -f /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index2/* /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index/
mv -f /opt/1panel/apps/openresty/openresty/www/sites/random-api.net/index2/* /opt/1panel/apps/openresty/openresty/www/sites/random-api.czl.net/index/
# 删除 index2 文件夹
rm -rf /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index2
rm -rf /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.net/index2
# 设置目录及其子文件的所有权和权限
chown -R 1000:1000 /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index
chmod -R 0755 /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index
chown -R 1000:1000 /opt/1panel/apps/openresty/openresty/www/sites/random-api.czl.net/index
chmod -R 0755 /opt/1panel/apps/openresty/openresty/www/sites/random-api.czl.net/index
# 清理临时文件
rm /tmp/deployment.zip

4
eo.js
View File

@ -1,5 +1,5 @@
// 外部 JSON 文件的 URL
const CSV_PATHS_URL = 'https://random-api-file.czl.net/url.json';
const CSV_PATHS_URL = 'https://random-api.czl.net/url.json';
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
@ -58,7 +58,7 @@ async function handleRequest(request) {
}
} else {
// 请求路径不在配置中,返回默认首页
const indexHtmlResponse = await fetch('https://random-api-file.czl.net');
const indexHtmlResponse = await fetch('https://random-api.czl.net');
return new Response(indexHtmlResponse.body, {
headers: { 'Content-Type': 'text/html' },
});

View File

@ -6,12 +6,16 @@ const winston = require('winston');
require('winston-daily-rotate-file');
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
const path = require('path'); // 添加这行来导入 path 模块
const app = express();
const port = 5003;
// 设置静态文件目录
app.use(express.static(path.join(__dirname, 'public')));
// 外部 JSON 文件的 URL
const CSV_PATHS_URL = 'https://random-api-file.czl.net/url.json';
const CSV_PATHS_URL = 'https://random-api.czl.net/url.json';
// 设置缓存
let csvPathsCache = null;
@ -151,7 +155,7 @@ async function handleRequest(req, res) {
return res.status(500).send('CSV file could not be fetched.');
}
} else {
const indexHtmlResponse = await fetch('https://random-api-file.czl.net');
const indexHtmlResponse = await fetch('https://random-api.czl.net');
const indexHtml = await indexHtmlResponse.text();
return res.type('html').send(indexHtml);
}

View File

@ -110,7 +110,7 @@
});
// 异步加载 index.md 文件内容
fetch('https://random-api-file.czl.net/index.md')
fetch('./index.md')
.then(response => response.text())
.then(markdownText => {
// 渲染 Markdown 内容

15
nodejs/public/url.json Normal file
View File

@ -0,0 +1,15 @@
{
"pic": {
"all": "https://random-api.czl.net/url/pic/all.csv",
"fjht": "https://random-api.czl.net/url/pic/fjht.csv",
"czlwb": "https://random-api.czl.net/url/pic/czl-website-background.csv",
"truegirl": "https://random-api.czl.net/url/pic/truegirl.csv",
"ecy": "https://random-api.czl.net/url/pic/ecy.csv",
"ecy1": "https://random-api.czl.net/url/pic/ecy1.csv",
"ecy2": "https://random-api.czl.net/url/pic/ecy2.csv"
},
"video": {
"all": "https://random-api.czl.net/url/video/all.csv"
}
}

View File

@ -1,15 +0,0 @@
{
"pic": {
"all": "https://random-api-file.czl.net/url/pic/all.csv",
"fjht": "https://random-api-file.czl.net/url/pic/fjht.csv",
"czlwb": "https://random-api-file.czl.net/url/pic/czl-website-background.csv",
"truegirl": "https://random-api-file.czl.net/url/pic/truegirl.csv",
"ecy": "https://random-api-file.czl.net/url/pic/ecy.csv",
"ecy1": "https://random-api-file.czl.net/url/pic/ecy1.csv",
"ecy2": "https://random-api-file.czl.net/url/pic/ecy2.csv"
},
"video": {
"all": "https://random-api-file.czl.net/url/video/all.csv"
}
}

View File

@ -1,5 +1,5 @@
// 外部 JSON 文件的 URL
const CSV_PATHS_URL = 'https://random-api-file.czl.net/url.json';
const CSV_PATHS_URL = 'https://random-api.czl.net/url.json';
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
@ -58,7 +58,7 @@ async function handleRequest(request) {
}
} else {
// 请求路径不在配置中,返回默认首页
const indexHtmlResponse = await fetch('https://random-api-file.czl.net');
const indexHtmlResponse = await fetch('https://random-api.czl.net');
return new Response(indexHtmlResponse.body, {
headers: { 'Content-Type': 'text/html' },
});