Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

更新到3.1.6后,在中间件中调用ctx.request.body为undefined #529

Open
dwyanewang opened this issue Jun 21, 2023 · 1 comment
Open

Comments

@dwyanewang
Copy link

更新到3.1.6后,在中间件中调用ctx.request.body为undefined
项目源码地址:https://github.com/dwyanewang/midwayjs-test

复现流程

  1. 下载官方示例
npx degit https://github.com/midwayjs/hooks/examples/api-bundle ./hooks-app
  1. 新增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)
}
  1. 在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,
    },
  ],
})
  1. 将hooks版本改为3.1.6
    image
    image
  2. 在index.ts中新增test接口
export const test = Api(Post('/api/test'), async () => {
  const ctx = useContext()

  return {
    message: 'Hello World!',
    ip: ctx.ip,
  }
})
  1. 然后运行项目,测试test接口
    image
    image
  2. 更改hooks版本为3.0.1
    image
    image
  3. 然后运行项目,测试test接口
    image
    image
@dwyanewang
Copy link
Author

是什么问题可以先说明下吗

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant