File tree 6 files changed +55
-15
lines changed
6 files changed +55
-15
lines changed Original file line number Diff line number Diff line change 1
- import { Auth } from " ../../src/schemas/auth.ts" ;
1
+ import { Auth } from ' ../../src/schemas/auth.ts'
2
2
3
- declare module " fastify" {
4
- export interface FastifyRequest {
5
- user : Auth
6
- }
3
+ declare module ' fastify' {
4
+ export interface FastifyRequest {
5
+ user : Auth
6
+ }
7
7
}
Original file line number Diff line number Diff line change @@ -13,4 +13,4 @@ declare global {
13
13
}
14
14
}
15
15
16
- export { } ;
16
+ export { }
Original file line number Diff line number Diff line change 49
49
"react-dom" : " ^18.3.1"
50
50
},
51
51
"devDependencies" : {
52
- "@types/node" : " ^22.0.0" ,
53
- "@types/react" : " ^18.3.4" ,
54
- "@types/react-dom" : " ^18.3.0" ,
55
- "eslint" : " ^9.4.0" ,
52
+ "@types/node" : " ^22.5.5" ,
53
+ "eslint" : " ^9.11.0" ,
56
54
"fastify-tsconfig" : " ^2.0.0" ,
57
- "mysql2" : " ^3.10.1 " ,
55
+ "mysql2" : " ^3.11.3 " ,
58
56
"neostandard" : " ^0.11.5" ,
59
57
"tap" : " ^21.0.1" ,
60
- "typescript" : " ^5.4.5 "
58
+ "typescript" : " ^5.6.2 "
61
59
}
62
60
}
Original file line number Diff line number Diff line change @@ -60,10 +60,14 @@ export default async function serviceApp (
60
60
'Unhandled error occurred'
61
61
)
62
62
63
- const statusCode = err . statusCode ?? 500
64
- reply . code ( statusCode )
63
+ reply . code ( err . statusCode ?? 500 )
65
64
66
- return { message : 'Internal Server Error' }
65
+ let message = 'Internal Server Error'
66
+ if ( err . statusCode === 401 ) {
67
+ message = err . message
68
+ }
69
+
70
+ return { message }
67
71
} )
68
72
69
73
// An attacker could search for valid URLs if your 404 error handling is not rate limited.
Original file line number Diff line number Diff line change
1
+ import {
2
+ FastifyPluginAsyncTypebox ,
3
+ Type
4
+ } from '@fastify/type-provider-typebox'
5
+
6
+ const plugin : FastifyPluginAsyncTypebox = async ( fastify ) => {
7
+ fastify . get (
8
+ '/' ,
9
+ {
10
+ schema : {
11
+ response : {
12
+ 200 : Type . Object ( {
13
+ message : Type . String ( )
14
+ } )
15
+ }
16
+ }
17
+ } ,
18
+ async function ( ) {
19
+ return { message : 'Welcome to the official fastify demo!' }
20
+ }
21
+ )
22
+ }
23
+
24
+ export default plugin
Original file line number Diff line number Diff line change
1
+ import { test } from 'node:test'
2
+ import assert from 'node:assert'
3
+ import { build } from '../helper.js'
4
+
5
+ test ( 'GET /' , async ( t ) => {
6
+ const app = await build ( t )
7
+ const res = await app . inject ( {
8
+ url : '/'
9
+ } )
10
+
11
+ assert . deepStrictEqual ( JSON . parse ( res . payload ) , {
12
+ message : 'Welcome to the official fastify demo!'
13
+ } )
14
+ } )
You can’t perform that action at this time.
0 commit comments