File tree Expand file tree Collapse file tree 6 files changed +55
-16
lines changed Expand file tree Collapse file tree 6 files changed +55
-16
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 37
37
"@fastify/swagger-ui" : " ^5.0.1" ,
38
38
"@fastify/type-provider-typebox" : " ^5.0.0" ,
39
39
"@fastify/under-pressure" : " ^9.0.1" ,
40
- "@fastify/vite" : " ^7.0.1" ,
41
40
"@sinclair/typebox" : " ^0.33.12" ,
42
41
"@vitejs/plugin-react" : " ^4.3.1" ,
43
42
"concurrently" : " ^9.0.1" ,
49
48
"react-dom" : " ^18.3.1"
50
49
},
51
50
"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" ,
51
+ "@types/node" : " ^22.5.5" ,
52
+ "eslint" : " ^9.11.0" ,
56
53
"fastify-tsconfig" : " ^2.0.0" ,
57
- "mysql2" : " ^3.10.1 " ,
54
+ "mysql2" : " ^3.11.3 " ,
58
55
"neostandard" : " ^0.11.5" ,
59
56
"tap" : " ^21.0.1" ,
60
- "typescript" : " ^5.4.5 "
57
+ "typescript" : " ^5.6.2 "
61
58
}
62
59
}
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