This commit is contained in:
2026-01-26 01:09:20 +08:00
parent 911f03b4bd
commit 0f8986b491
5 changed files with 14 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package",
"name": "@kevisual/router",
"version": "0.0.61",
"version": "0.0.62",
"description": "",
"type": "module",
"main": "./dist/router.js",

View File

@@ -614,8 +614,7 @@ export class QueryRouter {
}
/**
* 等待程序运行, 获取到message的数据,就执行
* params 是预设参数默认path为main
*
* params 是预设参数
* emitter = process
* -- .exit
* -- .on

View File

@@ -3,7 +3,8 @@ import { Mini } from "../route.ts";
const app = new Mini();
app.route({
path: 'main'
path: 'main',
id: 'abc'
}).define(async (ctx) => {
ctx.body = {
a: '123'

View File

@@ -51,6 +51,7 @@ export const runCode = async (tsPath: string, params: RunCodeParams = {}): Promi
import path from 'node:path'
const res =await runCode(path.join(process.cwd(), './src/test/mini.ts'), {
// path: 'main'
// id: 'abc'
})
console.log('res', res)

View File

@@ -71,12 +71,19 @@ export const listenProcess = async ({ app, mockProcess, params, timeout = 10 * 6
* 如果不提供path默认是main
*/
const {
path = 'main',
payload = {},
...rest
} = await getParams()
const msg = { ...params, ...rest, payload: { ...params?.payload, ...payload } }
/**
* 如果没有提供path和id默认取第一个路由, 而且路由path不是router的
*/
if (!msg.path && !msg.id) {
const route = app.routes.find(r => r.path !== 'router')
msg.id = route?.id
}
// 执行主要逻辑
const result = await app.run({ path, ...params, ...rest, payload: { ...params?.payload, ...payload } })
const result = await app.run(msg)
// 发送结果回主进程
const response = {
success: true,