Open dwyanewang opened 1 year ago
更新到3.1.6后,在中间件中调用ctx.request.body为undefined 项目源码地址:https://github.com/dwyanewang/midwayjs-test
npx degit https://github.com/midwayjs/hooks/examples/api-bundle ./hooks-app
import {useContext} from '@midwayjs/hooks' import {Context} from '@midwayjs/koa'
export default async (next: any) => { const ctx = useContext() console.log(111, ctx.request.body)
await next()
console.log(222, ctx.request.body) }
3. 在configuration.ts中引入 ```typescript import {createConfiguration, hooks} from '@midwayjs/hooks' import {MidwayConfig} from '@midwayjs/core' import * as Koa from '@midwayjs/koa' import Test from './test' export default createConfiguration({ imports: [Koa, hooks({middleware: [Test]})], importConfigs: [ { default: { keys: 'session_keys', koa: { port: 7002, }, } as MidwayConfig, }, ], })
在index.ts中新增test接口
export const test = Api(Post('/api/test'), async () => { const ctx = useContext() return { message: 'Hello World!', ip: ctx.ip, } })
是什么问题可以先说明下吗
更新到3.1.6后,在中间件中调用ctx.request.body为undefined 项目源码地址:https://github.com/dwyanewang/midwayjs-test
复现流程
export default async (next: any) => { const ctx = useContext()
console.log(111, ctx.request.body)
await next()
console.log(222, ctx.request.body) }
在index.ts中新增test接口