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

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

@dwyanewang

Description

@dwyanewang

更新到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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions