temp
This commit is contained in:
38
.github/workflows/publish.yml
vendored
38
.github/workflows/publish.yml
vendored
@@ -1,38 +0,0 @@
|
|||||||
name: Publish to npm
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*.*.*' # 当推送带有版本号的 tag 时触发,例如 v1.0.0
|
|
||||||
workflow_dispatch: # 添加手动触发器
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
publish:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
# Step 1: Clone current Git repository
|
|
||||||
- name: Checkout this repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
# Step 3: Setup Node.js and install dependencies
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: '20.6'
|
|
||||||
registry-url: 'https://registry.npmjs.org/'
|
|
||||||
cache: 'npm' # 启用 npm 缓存,提高安装速度
|
|
||||||
- name: Configure npm authentication
|
|
||||||
run: npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm install --no-save
|
|
||||||
- name: Build project
|
|
||||||
run: npm run build
|
|
||||||
# Step 6: 发布到 npm
|
|
||||||
- name: Publish package
|
|
||||||
run: npm publish
|
|
||||||
env:
|
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
||||||
# Step 7: 发布成功后,更新版本标签
|
|
||||||
# - name: Create Git tag
|
|
||||||
# run: |
|
|
||||||
# TAG="v$(node -p -e "require('./package.json').version")"
|
|
||||||
# git tag $TAG
|
|
||||||
# git push origin $TAG
|
|
||||||
12
package.json
12
package.json
@@ -21,21 +21,21 @@
|
|||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "abearxiong",
|
"author": "abearxiong",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"packageManager": "pnpm@10.26.2",
|
"packageManager": "pnpm@10.28.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@kevisual/local-proxy": "^0.0.8",
|
"@kevisual/local-proxy": "^0.0.8",
|
||||||
"@kevisual/query": "^0.0.33",
|
"@kevisual/query": "^0.0.35",
|
||||||
"@rollup/plugin-alias": "^6.0.0",
|
"@rollup/plugin-alias": "^6.0.0",
|
||||||
"@rollup/plugin-commonjs": "29.0.0",
|
"@rollup/plugin-commonjs": "29.0.0",
|
||||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||||
"@rollup/plugin-typescript": "^12.3.0",
|
"@rollup/plugin-typescript": "^12.3.0",
|
||||||
"@types/bun": "^1.3.5",
|
"@types/bun": "^1.3.5",
|
||||||
"@types/node": "^25.0.3",
|
"@types/node": "^25.0.7",
|
||||||
"@types/send": "^1.2.1",
|
"@types/send": "^1.2.1",
|
||||||
"@types/xml2js": "^0.4.14",
|
"@types/xml2js": "^0.4.14",
|
||||||
"@types/ws": "^8.18.1",
|
"@types/ws": "^8.18.1",
|
||||||
"nanoid": "^5.1.6",
|
"nanoid": "^5.1.6",
|
||||||
"rollup": "^4.54.0",
|
"rollup": "^4.55.1",
|
||||||
"rollup-plugin-dts": "^6.3.0",
|
"rollup-plugin-dts": "^6.3.0",
|
||||||
"ts-loader": "^9.5.4",
|
"ts-loader": "^9.5.4",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
"tsx": "^4.21.0",
|
"tsx": "^4.21.0",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"xml2js": "^0.6.2",
|
"xml2js": "^0.6.2",
|
||||||
"zod": "^4.2.1",
|
"zod": "^4.3.5",
|
||||||
"eventemitter3": "^5.0.1",
|
"eventemitter3": "^5.0.1",
|
||||||
"ws": "npm:@kevisual/ws"
|
"ws": "npm:@kevisual/ws"
|
||||||
},
|
},
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"path-to-regexp": "^8.3.0",
|
"path-to-regexp": "^8.3.0",
|
||||||
"selfsigned": "^5.4.0",
|
"selfsigned": "^5.5.0",
|
||||||
"send": "^1.2.1"
|
"send": "^1.2.1"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
|
|||||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -8,9 +8,6 @@ importers:
|
|||||||
|
|
||||||
.:
|
.:
|
||||||
dependencies:
|
dependencies:
|
||||||
eventemitter3:
|
|
||||||
specifier: ^5.0.1
|
|
||||||
version: 5.0.1
|
|
||||||
path-to-regexp:
|
path-to-regexp:
|
||||||
specifier: ^8.3.0
|
specifier: ^8.3.0
|
||||||
version: 8.3.0
|
version: 8.3.0
|
||||||
@@ -54,6 +51,9 @@ importers:
|
|||||||
'@types/xml2js':
|
'@types/xml2js':
|
||||||
specifier: ^0.4.14
|
specifier: ^0.4.14
|
||||||
version: 0.4.14
|
version: 0.4.14
|
||||||
|
eventemitter3:
|
||||||
|
specifier: ^5.0.1
|
||||||
|
version: 5.0.1
|
||||||
nanoid:
|
nanoid:
|
||||||
specifier: ^5.1.6
|
specifier: ^5.1.6
|
||||||
version: 5.1.6
|
version: 5.1.6
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export { App } from './app.ts';
|
|||||||
export * from './router-define.ts';
|
export * from './router-define.ts';
|
||||||
|
|
||||||
|
|
||||||
export {
|
export type {
|
||||||
RouterReq,
|
RouterReq,
|
||||||
RouterRes,
|
RouterRes,
|
||||||
OnWebSocketFn,
|
OnWebSocketFn,
|
||||||
@@ -32,3 +32,5 @@ export {
|
|||||||
HttpListenerFun,
|
HttpListenerFun,
|
||||||
OnListener,
|
OnListener,
|
||||||
} from './server/server-type.ts';
|
} from './server/server-type.ts';
|
||||||
|
|
||||||
|
export { loadTS } from './auto/load-ts.ts';
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
// TODO: Implement IOApp
|
|
||||||
export class IOApp {
|
|
||||||
constructor() {
|
|
||||||
console.log('IoApp');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@ export type AltNames = {
|
|||||||
value?: string;
|
value?: string;
|
||||||
ip?: string;
|
ip?: string;
|
||||||
};
|
};
|
||||||
export const createCert = (attrs: Attributes[] = [], altNames: AltNames[] = []) => {
|
export const createCert = async(attrs: Attributes[] = [], altNames: AltNames[] = []) => {
|
||||||
let attributes = [
|
let attributes = [
|
||||||
{ name: 'countryName', value: 'CN' }, // 国家代码
|
{ name: 'countryName', value: 'CN' }, // 国家代码
|
||||||
{ name: 'stateOrProvinceName', value: 'ZheJiang' }, // 州名
|
{ name: 'stateOrProvinceName', value: 'ZheJiang' }, // 州名
|
||||||
@@ -51,7 +51,7 @@ export const createCert = (attrs: Attributes[] = [], altNames: AltNames[] = [])
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
const pems = generate(attributes, options);
|
const pems = await generate(attributes, options);
|
||||||
return {
|
return {
|
||||||
key: pems.private,
|
key: pems.private,
|
||||||
cert: pems.cert,
|
cert: pems.cert,
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
const http = require('http');
|
|
||||||
const fs = require('fs').promises;
|
|
||||||
const path = require('path');
|
|
||||||
const fetch = require('node-fetch'); // 如果使用 Node.js 18 以上版本,可以改用内置 fetch
|
|
||||||
const url = require('url');
|
|
||||||
|
|
||||||
// 配置远端静态文件服务器和本地缓存目录
|
|
||||||
const remoteServer = 'https://example.com/static'; // 远端服务器的 URL
|
|
||||||
const cacheDir = path.join(__dirname, 'cache'); // 本地缓存目录
|
|
||||||
const PORT = process.env.PORT || 3000;
|
|
||||||
|
|
||||||
// 确保本地缓存目录存在
|
|
||||||
fs.mkdir(cacheDir, { recursive: true }).catch(console.error);
|
|
||||||
|
|
||||||
// 获取文件的 content-type
|
|
||||||
function getContentType(filePath) {
|
|
||||||
const extname = path.extname(filePath);
|
|
||||||
const contentType = {
|
|
||||||
'.html': 'text/html',
|
|
||||||
'.js': 'text/javascript',
|
|
||||||
'.css': 'text/css',
|
|
||||||
'.json': 'application/json',
|
|
||||||
'.png': 'image/png',
|
|
||||||
'.jpg': 'image/jpg',
|
|
||||||
'.gif': 'image/gif',
|
|
||||||
'.svg': 'image/svg+xml',
|
|
||||||
'.wav': 'audio/wav',
|
|
||||||
'.mp4': 'video/mp4'
|
|
||||||
};
|
|
||||||
return contentType[extname] || 'application/octet-stream';
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理请求文件
|
|
||||||
async function serveFile(filePath, remoteUrl, res) {
|
|
||||||
try {
|
|
||||||
// 检查文件是否存在于本地缓存中
|
|
||||||
const fileContent = await fs.readFile(filePath);
|
|
||||||
res.writeHead(200, { 'Content-Type': getContentType(filePath) });
|
|
||||||
res.end(fileContent, 'utf-8');
|
|
||||||
} catch (err) {
|
|
||||||
if (err.code === 'ENOENT') {
|
|
||||||
// 本地缓存中不存在,向远端服务器请求文件
|
|
||||||
try {
|
|
||||||
const response = await fetch(remoteUrl);
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
// 远端请求成功,获取文件内容
|
|
||||||
const data = await response.buffer();
|
|
||||||
|
|
||||||
// 将文件缓存到本地
|
|
||||||
await fs.writeFile(filePath, data);
|
|
||||||
|
|
||||||
// 返回文件内容
|
|
||||||
res.writeHead(200, { 'Content-Type': getContentType(filePath) });
|
|
||||||
res.end(data, 'utf-8');
|
|
||||||
} else {
|
|
||||||
// 远端文件未找到或错误,返回 404
|
|
||||||
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
||||||
res.end(`Error 404: File not found at ${remoteUrl}`);
|
|
||||||
}
|
|
||||||
} catch (fetchErr) {
|
|
||||||
// 处理请求错误
|
|
||||||
res.writeHead(500, { 'Content-Type': 'text/plain' });
|
|
||||||
res.end(`Server Error: Unable to fetch ${remoteUrl}`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 其他文件系统错误
|
|
||||||
res.writeHead(500, { 'Content-Type': 'text/plain' });
|
|
||||||
res.end(`Server Error: ${err.message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建 HTTP 服务器
|
|
||||||
http.createServer(async (req, res) => {
|
|
||||||
let reqPath = req.url;
|
|
||||||
|
|
||||||
// 如果路径是根路径 `/`,将其设置为 `index.html`
|
|
||||||
if (reqPath === '/') reqPath = '/index.html';
|
|
||||||
|
|
||||||
// 构建本地缓存路径和远端 URL
|
|
||||||
const localFilePath = path.join(cacheDir, reqPath); // 本地文件路径
|
|
||||||
const remoteFileUrl = url.resolve(remoteServer, reqPath); // 远端文件 URL
|
|
||||||
|
|
||||||
// 根据请求路径处理文件或返回 index.html(单页面应用处理)
|
|
||||||
await serveFile(localFilePath, remoteFileUrl, res);
|
|
||||||
|
|
||||||
// 单页面应用的路由处理
|
|
||||||
if (res.headersSent) return; // 如果响应已发送,不再处理
|
|
||||||
|
|
||||||
// 如果未匹配到任何文件,返回 index.html
|
|
||||||
const indexFilePath = path.join(cacheDir, 'index.html');
|
|
||||||
const indexRemoteUrl = url.resolve(remoteServer, '/index.html');
|
|
||||||
await serveFile(indexFilePath, indexRemoteUrl, res);
|
|
||||||
}).listen(PORT, () => {
|
|
||||||
console.log(`Server running at http://localhost:${PORT}`);
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user