feat: add export and import

This commit is contained in:
2024-10-25 19:41:01 +08:00
parent 6f0faba703
commit 158b12d811
10 changed files with 115 additions and 17 deletions

View File

@@ -11,7 +11,7 @@
"license": "ISC",
"description": "",
"dependencies": {
"@abearxiong/router": "../.."
"@kevisual/router": "link:../.."
},
"devDependencies": {
"ts-node": "^10.9.2",

View File

@@ -1,4 +1,4 @@
import { App } from '@abearxiong/router';
import { App } from '@kevisual/router';
const app = new App();

View File

@@ -1,4 +1,4 @@
import { Route, App } from '@abearxiong/router';
import { Route, App } from '@kevisual/router';
const app = new App({ io: true });
app.listen(4002);

View File

@@ -1,4 +1,4 @@
import { Route, App } from '@abearxiong/router';
import { Route, App } from '@kevisual/router';
const app = new App();
app.listen(4003);

View File

@@ -1,4 +1,4 @@
import { QueryRouter, Route, Server } from '@abearxiong/router';
import { QueryRouter, Route, Server } from '@kevisual/router';
const router = new QueryRouter();

View File

@@ -0,0 +1,76 @@
import { App } from '@kevisual/router';
const app1 = new App();
app1
.route({
path: 'app1',
key: '01',
})
.define(async (ctx) => {
ctx.body = '01';
return ctx;
})
.addTo(app1);
app1
.route({
path: 'app1',
key: '02',
})
.define(async (ctx) => {
ctx.body = '02';
return ctx;
})
.addTo(app1);
const app2 = new App();
app2
.route({
path: 'app2',
key: '01',
})
.define(async (ctx) => {
ctx.body = 'app2' + '01';
return ctx;
})
.addTo(app2);
app2
.route({
path: 'app2',
key: '02',
})
.define(async (ctx) => {
ctx.body = 'app2' + '02';
return ctx;
})
.addTo(app2);
const app3 = new App();
app3
.route({
path: 'app3',
key: '01',
})
.define(async (ctx) => {
ctx.body = 'app3' + '01';
return ctx;
})
.addTo(app3);
const app = new App();
app.importRoutes(app1.exportRoutes());
app.importRoutes(app2.exportRoutes());
app.importApp(app3);
app.listen(4003, () => {
console.log(`http://localhost:4003/api/router?path=app1&key=02`);
console.log(`http://localhost:4003/api/router?path=app1&key=01`);
console.log(`http://localhost:4003/api/router?path=app2&key=02`);
console.log(`http://localhost:4003/api/router?path=app2&key=01`);
console.log(`http://localhost:4003/api/router?path=app3&key=01`);
});

View File

@@ -1,4 +1,4 @@
import { Route, QueryRouter, RouteContext } from '@abearxiong/router';
import { Route, QueryRouter, RouteContext } from '@kevisual/router';
const qr = new QueryRouter();
qr.add(