This repository was archived by the owner on Nov 1, 2023. It is now read-only.
Description 更新到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
新增test中间件
import { useContext } from '@midwayjs/hooks'
import { Context } from '@midwayjs/koa'
export default async ( next : any ) => {
const ctx = useContext < Context > ( )
console . log ( 111 , ctx . request . body )
await next ( )
console . log ( 222 , ctx . request . body )
}
在configuration.ts中引入
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 ,
} ,
] ,
} )
将hooks版本改为3.1.6
在index.ts中新增test接口
export const test = Api ( Post ( '/api/test' ) , async ( ) => {
const ctx = useContext ( )
return {
message : 'Hello World!' ,
ip : ctx . ip ,
}
} )
然后运行项目,测试test接口
更改hooks版本为3.0.1
然后运行项目,测试test接口
Reactions are currently unavailable
更新到3.1.6后,在中间件中调用ctx.request.body为undefined
项目源码地址:https://github.com/dwyanewang/midwayjs-test
复现流程