feat: add metadata and middleware add preivew middleware

This commit is contained in:
2025-02-26 11:26:52 +08:00
parent 986b5687c4
commit 1c3e65df8a
4 changed files with 100 additions and 23 deletions

View File

@@ -3,7 +3,7 @@ import { readFileSync } from 'fs';
const app = new App({
serverOptions: {
cors: {},
isHTTPS: true,
httpType: 'https',
httpsKey: readFileSync('https-key.pem', 'utf8'),
httpsCert: readFileSync('https-cert.pem', 'utf-8'),
},

View File

@@ -0,0 +1,52 @@
import { Route, App } from '@kevisual/router';
import { readFileSync } from 'fs';
const app = new App({
serverOptions: {
cors: {},
httpType: 'https',
httpsKey: readFileSync('https-key.pem', 'utf8'),
httpsCert: readFileSync('https-cert.pem', 'utf-8'),
},
});
app
.route({
path: 'demo',
key: '01',
})
.define(async (ctx) => {
ctx.token = '01';
ctx.body = '01';
ctx.state.t01 = '01';
console.log('state01', ctx.state);
})
.addTo(app);
app
.route({
path: 'demo',
key: '02',
middleware: [{ path: 'demo', key: '01' } as Route],
})
.define(async (ctx) => {
ctx.body = '02';
ctx.state.t02 = '02';
console.log('state02', ctx.state, 't', ctx.token);
})
.addTo(app);
app
.route({
path: 'demo',
key: '03',
middleware: [{ path: 'demo', key: '02' } as Route],
})
.define(async (ctx) => {
ctx.body = '03';
console.log('state03', ctx.state);
})
.addTo(app);
app.call({ path: 'demo', key: '03' }).then((ctx) => {
console.log('result', ctx.body);
});