mirror of
https://github.com/zoriya/elysia.git
synced 2026-08-15 18:44:25 +00:00
22 lines
445 B
TypeScript
22 lines
445 B
TypeScript
import { Elysia } from '../src'
|
|
|
|
new Elysia()
|
|
// Create global mutable state
|
|
.state('counter', 0)
|
|
// Increase counter by 1 on every request on any handler
|
|
.onTransform(({ store }) => {
|
|
store.counter++
|
|
})
|
|
.get('/', ({ store: { counter } }) => counter, {
|
|
// Increase counter only when this handler is called
|
|
transform: [
|
|
({ store }) => {
|
|
store.counter++
|
|
},
|
|
({ store }) => {
|
|
store.counter++
|
|
}
|
|
]
|
|
})
|
|
.listen(3000)
|