-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbasic.ts
85 lines (81 loc) · 1.97 KB
/
basic.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { swagger } from '@elysiajs/swagger'
import { Elysia } from 'elysia'
import logixlysia from '../src/index'
const app = new Elysia({
name: 'Basic Example'
})
.use(
swagger({
exclude: '/'
})
)
.use(
logixlysia({
config: {
showStartupMessage: true,
startupMessageFormat: 'simple',
timestamp: {
translateTime: 'yyyy-mm-dd HH:MM:ss.SSS'
},
logFilePath: './logs/example.log',
ip: true,
customLogFormat:
'🦊 {now} {level} {duration} {method} {pathname} {status} {message} {ip}'
// logFilter: {
// level: ['ERROR', 'WARNING'],
// status: [500, 404],
// method: 'GET'
// }
}
})
)
.get('/', () => {
return { message: 'Welcome to Basic Elysia with Logixlysia' }
})
.get('/success/:id', ({ params: { id } }) => {
return {
id,
message: `Successfully retrieved item ${id}`
}
})
.get('/error', () => {
throw new Error('Internal Server Error')
})
.get('/custom-error', () => {
throw { status: 503, message: 'Service Unavailable' }
})
.post('/items', ({ body }) => {
return {
message: 'Item created',
data: body
}
})
.put('/items/:id', ({ params: { id }, body }) => {
return {
message: `Item ${id} updated`,
data: body
}
})
.patch('/items/:id', ({ params: { id }, body }) => {
return {
message: `Item ${id} partially updated`,
data: body
}
})
.delete('/items/:id', ({ params: { id } }) => {
return {
message: `Item ${id} deleted`
}
})
.post('/status', ({ set }) => {
set.status = 201 // Use number status code
return { message: 'Created with 201 status' }
})
.get('/rate-limited', ({ set }) => {
set.status = 'Too Many Requests' // Use string status code
return { message: 'Too Many Requests' }
})
app.listen(3000)
// header for testing
// key: "Authorization"
// value: "Bearer 1234567890"