# Decorator State
Decorator operation input response koaModule | import { State } from "@tsed/platform-koa" |
---|---|
Source | /packages/platform-koa/src/decorators/state.ts |
# Overview
function State(expression: string): ParameterDecorator;
export function State(): ParameterDecorator;
Param | Type | Description |
---|---|---|
expression | string | The path of the property to get. |
# Description
State return the value from koa.ctx.state object.
# Example
@Middleware()
class StateMiddleware {
use(@State() state: any) {
// set some on locals
state.user = "user"
}
}
@Controller('/')
@UseBefore(StateMiddleware)
class MyCtrl {
@Get('/')
@Render('home.ejs') // will use locals and returned data to render the page
get(@State('user') user: any) {
console.log('user', user);
return {
description: 'Hello world'
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Other topics
- Session & cookies
- Passport.js
- TypeORM
- Mongoose
- GraphQL
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- Throw HTTP Exceptions
- Customize 404
- AWS
- Seq
- OIDC
- Stripe
- Controllers
- Providers
- Model
- JsonMapper
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Exceptions
- Hooks
- Response Filter
- Injection scopes
- Custom providers
- Custom endpoint decorator
- Testing