feat: 更新sign的模块

This commit is contained in:
2024-11-16 12:34:08 +08:00
parent 780d744a16
commit 926c0a09cd
8 changed files with 159 additions and 8 deletions

View File

@@ -0,0 +1,35 @@
import { Route, App } from '@kevisual/router';
import { readFileSync } from 'fs';
const app = new App({
serverOptions: {
cors: {},
isHTTPS: true,
httpsKey: readFileSync('https-key.pem', 'utf8'),
httpsCert: readFileSync('https-cert.pem', 'utf-8'),
},
});
app.listen(4003, '0.0.0.0', () => {
console.log(`http://localhost:4003/api/router?path=demo&key=02`);
console.log(`http://localhost:4003/api/router?path=demo&key=01`);
console.log(`https://192.168.31.220:4003/api/router?path=demo&key=01`);
});
const route01 = new Route('demo', '01');
route01.run = async (ctx) => {
ctx.body = '01';
return ctx;
};
app.use(
'demo',
async (ctx) => {
ctx.body = '01';
return ctx;
},
{ key: '01' },
);
const route02 = new Route('demo', '02');
route02.run = async (ctx) => {
ctx.body = '02';
return ctx;
};
app.addRoute(route02);

View File

@@ -0,0 +1,6 @@
import { createCert } from '@kevisual/router/sign';
import { writeFileSync } from 'fs';
const { key, cert } = createCert();
writeFileSync('https-key.pem', key);
writeFileSync('https-cert.pem', cert);