Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ You can also run equivalent commands inside `apps/docs` with `pnpm run <script>`

## i18n workflow

This docs app supports multiple locales (`en`, `ko`, `de`, `fr`).
This docs app supports multiple locales (`en`, `ko`, `de`, `fr`, `ru`, `ja`, `es`, `zh-Hans`).

```bash
# extract translation files
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/docs/advanced/custom-transformer.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ReportRequest {
class ProductQuery {
@Query('q')
@Transform((value: string) => value.toLowerCase().trim())
@IsNotEmpty()
@MinLength(1)
searchTerm!: string

@Query()
Expand Down Expand Up @@ -155,4 +155,4 @@ class FilterRequest {

// GET /filter?active=yes → { active: true }
// GET /filter?active=0 → { active: false }
```
```
3 changes: 2 additions & 1 deletion apps/docs/docs/advanced/nested-binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Express-Cargo allows you to handle nested objects in requests, automatically bin

```typescript
import express, { Request, Response } from 'express'
import { Body, bindingCargo, getCargo } from 'express-cargo'
import { Body, Type, bindingCargo, getCargo } from 'express-cargo'

// 1. Define nested Object
class Profile {
Expand All @@ -16,6 +16,7 @@ class Profile {

class ExampleObject {
@Body('profile')
@Type(() => Profile)
profile!: Profile
}

Expand Down
3 changes: 2 additions & 1 deletion apps/docs/docs/examples/nested-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class UserInfoRequest {

```typescript
// order.request.ts
import { Body, Min, Max } from 'express-cargo'
import { Body, Min, Max, Type } from 'express-cargo'
import { UserInfoRequest } from './user.request'

export class OrderRequest {
Expand All @@ -53,6 +53,7 @@ export class OrderRequest {
quantity!: number

@Body('user')
@Type(() => UserInfoRequest)
user!: UserInfoRequest
}
```
Expand Down
22 changes: 15 additions & 7 deletions apps/docs/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ pnpm add reflect-metadata
#### 6-1. `src/app.ts`

```typescript
import express from 'express'
import { bindingCargo, getCargo, Body, Query, Header, Params, Min, Max, Equal, NotEqual, Prefix, Suffix } from 'express-cargo'
import errorHandlerRouter from './errorHandler'
import express, { Request, Response, NextFunction } from 'express'
import { bindingCargo, getCargo, Body, Equal, CargoValidationError } from 'express-cargo'

const app = express()

Expand All @@ -91,10 +90,6 @@ const port = process.env.PORT || 3000
app.use(express.json())
app.use(express.urlencoded({ extended: true }))

app.use(errorHandlerRouter)

app.listen(port, () => {console.log(`Example app listening on port ${port}`)})

class ExampleRequest {
@Body() // Extract fields from the request body
@Equal('1') // If the value is not "1", a validation error occurs
Expand All @@ -105,6 +100,19 @@ app.post('/example', bindingCargo(ExampleRequest), (req, res) => { // bindingCar
const cargo = getCargo<ExampleRequest>(req) // Return a validated type-safe object
res.json(cargo)
})

app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
if (err instanceof CargoValidationError) {
res.status(400).json({
errors: err.errors.map(error => error.message),
})
return
}

next(err)
})

app.listen(port, () => {console.log(`Example app listening on port ${port}`)})
```

### 7. Run
Expand Down
6 changes: 5 additions & 1 deletion apps/docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const config: Config = {
// may want to replace "en" with "zh-Hans".
i18n: {
defaultLocale: 'en',
locales: ['en', 'ko', 'de', 'fr', 'ru', 'ja', 'es'],
locales: ['en', 'ko', 'de', 'fr', 'ru', 'ja', 'es', 'zh-Hans'],
localeConfigs: {
en: {
label: 'English',
Expand Down Expand Up @@ -66,6 +66,10 @@ const config: Config = {
label: 'Español',
direction: 'ltr',
},
'zh-Hans': {
label: '简体中文',
direction: 'ltr',
},
},
},

Expand Down
Loading
Loading