@@ -2,6 +2,10 @@ import Fastify from 'fastify'
22import FastifyVite from '@fastify/vite'
33import FastifyFormBody from '@fastify/formbody'
44
5+ interface Database {
6+ todoList : string [ ]
7+ }
8+
59const server = Fastify ( {
610 logger : {
711 transport : {
@@ -10,35 +14,37 @@ const server = Fastify({
1014 }
1115} )
1216
13- // @ts -ignore
1417await server . register ( FastifyFormBody )
15- // @ts -ignore
18+
1619await server . register ( FastifyVite , {
1720 // TODO handle via CLI path argument with proper resolve
1821 root : process . cwd ( ) ,
1922 renderer : '@fastify/react' ,
2023} )
2124
22- // @ts -ignore
2325await server . vite . ready ( )
2426
25- server . decorate ( 'db' , {
27+ server . decorate < Database > ( 'db' , {
2628 todoList : [
2729 'Do laundry' ,
2830 'Respond to emails' ,
2931 'Write report' ,
3032 ]
3133} )
3234
33- server . put ( '/api/todo/items' , ( req , reply ) => {
34- // @ts -ignore
35- server . db . todoList . push ( req . body )
35+ server . put < {
36+ Body : string
37+ } > ( '/api/todo/items' , ( req , reply ) => {
38+ const db = server . getDecorator < Database > ( 'db' )
39+ db . todoList . push ( req . body )
3640 reply . send ( { ok : true } )
3741} )
3842
39- server . delete ( '/api/todo/items' , ( req , reply ) => {
40- // @ts -ignore
41- server . db . todoList . splice ( req . body , 1 )
43+ server . delete < {
44+ Body : number
45+ } > ( '/api/todo/items' , ( req , reply ) => {
46+ const db = server . getDecorator < Database > ( 'db' )
47+ db . todoList . splice ( req . body , 1 )
4248 reply . send ( { ok : true } )
4349} )
4450
0 commit comments