Skip to content

Commit

Permalink
docs: update busboy typo
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Sep 5, 2024
1 parent 5672afc commit 323ac15
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 15 deletions.
50 changes: 50 additions & 0 deletions site/blog/2024-08-29-release-3.17.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,56 @@ return new HttpServerResponse(this.ctx).fail().json('hello world');



## 类中间件复用

在之前,如果需要复用中间件,只能使用函数中间件。

```typescript
const mw = (ctx, next) => {
// ...
}

@Controller(/**/)
export class HomeController {

@Get('/', { middleware: [mw]})
async home() {}

@Get('/api', { middleware: [mw]})
async api() {}
}
```

但是如果希望用上继承,或者 `match``ignore` 功能的,则是类的行为更为方便。

这个版本框架提供了 `createMiddleware` 功能,保留原有的逻辑同时,可以创建出一个新的中间件实例。

```typescript

@Middleware()
export class ReportMiddleware implements IMiddleware<Context, NextFunction> {
// ...
}

@Controller(/**/)
export class HomeController {

@Get('/', { middleware: [createMiddleware(ReportMiddleware, {}, 'name1')]})
async home() {}

@Get('/api', { middleware: [createMiddleware(ReportMiddleware, {}, 'name2')]})
async api() {}
}
```

通过向 `createMiddleware` 传递不同的参数,以及中间件名字,就可以引用到不同的逻辑。

更多的细节,请查看 [Web中间件](/docs/middleware) 文档。





## 更多的变化

* 修复了一个多语言匹配 key 的问题
Expand Down
2 changes: 1 addition & 1 deletion site/docs/data_response.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class HomeController {
@Get('/')
async home() {
const filePath = join(__dirname, '../../package.json');
return new HttpServerResponse(this.ctx, 'application/json').file(filePath);
return new HttpServerResponse(this.ctx).file(filePath, 'application/json');
}
}
```
Expand Down
14 changes: 8 additions & 6 deletions site/docs/extensions/busboy.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import { UploadMiddleware } from '@midwayjs/busboy';
@Controller('/')
export class HomeController {

@Post('/upload', {middleares: [UploadMiddleware]})
@Post('/upload', { middleware: [UploadMiddleware] })
async upload(/*...*/) {
// ...
}
Expand Down Expand Up @@ -196,11 +196,13 @@ export class MainConfiguration {

## 配置

组件使用 `busboy` 作为配置的 key。

### 上传模式 - file

`file` 为默认值,也是框架的推荐值。

配置 upload 的 mode 为 `file` 字符串。
配置 mode 为 `file` 字符串。

```typescript
// src/config/config.default.ts
Expand All @@ -222,7 +224,7 @@ import { UploadFileInfo } from '@midwayjs/busboy';
@Controller('/')
export class HomeController {

@Post('/upload')
@Post('/upload', /*...*/)
async upload(@Files() files: Array<UploadFileInfo>, @Fields() fields: Record<string, string) {
/*
files = [
Expand Down Expand Up @@ -296,7 +298,7 @@ import { UploadStreamFileInfo } from '@midwayjs/busboy';
@Controller('/')
export class HomeController {

@Post('/upload')
@Post('/upload', /*...*/)
async upload(@Files() files: Array<UploadStreamFileInfo>, @Fields() fields: Record<string, string) {
/*
files = [
Expand Down Expand Up @@ -549,12 +551,12 @@ import { UploadFileInfo, UploadMiddleware } from '@midwayjs/busboy';
@Controller('/')
export class HomeController {
@Post('/upload1', { middlewares: [ createMiddleware(UploadMiddleware, {mode: 'file'}) ]})
@Post('/upload1', { middleware: [ createMiddleware(UploadMiddleware, {mode: 'file'}) ]})
async upload1(@Files() files Array<UploadFileInfo>) {
// ...
}
@Post('/upload2', { middlewares: [ createMiddleware(UploadMiddleware, {mode: 'stream'}) ]})
@Post('/upload2', { middleware: [ createMiddleware(UploadMiddleware, {mode: 'stream'}) ]})
async upload2(@Files() files Array<UploadFileInfo>) {
// ...
}
Expand Down
3 changes: 2 additions & 1 deletion site/docs/logger_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,9 @@ export default {
midwayLogger: {
default: {
transports: {
file: false,
json: {
// ...
fileLogName: 'midway-app.json.log'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import { UploadMiddleware } from '@midwayjs/busboy';
@Controller('/')
export class HomeController {

@Post('/upload', {middleares: [UploadMiddleware]})
@Post('/upload', { middleware: [UploadMiddleware] })
async upload(/*...*/) {
// ...
}
Expand Down Expand Up @@ -195,11 +195,13 @@ export class MainConfiguration {

## Configuration

The component uses `busboy` as the configuration key.

### Upload mode - file

`file` is the default value and the recommended value of the framework.

Configure the upload mode to be the `file` string.
Configure mode as a `file` string.

```typescript
// src/config/config.default.ts
Expand All @@ -221,7 +223,7 @@ import { UploadFileInfo } from '@midwayjs/busboy';
@Controller('/')
export class HomeController {

@Post('/upload')
@Post('/upload', /*...*/)
async upload(@Files() files: Array<UploadFileInfo>, @Fields() fields: Record<string, string) {
/*
files = [
Expand Down Expand Up @@ -292,7 +294,7 @@ import { UploadStreamFileInfo } from '@midwayjs/busboy';
@Controller('/')
export class HomeController {

@Post('/upload')
@Post('/upload', /*...*/)
async upload(@Files() files: Array<UploadStreamFileInfo>, @Fields() fields: Record<string, string) {
/*
files = [
Expand Down Expand Up @@ -538,12 +540,12 @@ import { UploadFileInfo, UploadMiddleware } from '@midwayjs/busboy';
@Controller('/')
export class HomeController {
@Post('/upload1', { middlewares: [ createMiddleware(UploadMiddleware, {mode: 'file'}) ]})
@Post('/upload1', { middleware: [ createMiddleware(UploadMiddleware, {mode: 'file'}) ]})
async upload1(@Files() files Array<UploadFileInfo>) {
// ...
}
@Post('/upload2', { middlewares: [ createMiddleware(UploadMiddleware, {mode: 'stream'}) ]})
@Post('/upload2', { middleware: [ createMiddleware(UploadMiddleware, {mode: 'stream'}) ]})
async upload2(@Files() files Array<UploadFileInfo>) {
// ...
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,9 @@ export default {
midwayLogger: {
default: {
transports: {
file: false,
json: {
// ...
fileLogName: 'midway-app.json.log'
}
}
}
Expand Down

0 comments on commit 323ac15

Please sign in to comment.