@@ -14,59 +14,58 @@ import { Logger } from "../service/logger.ts";
14
14
15
15
const apiKeys = Deno . env . get ( "API_KEYS" ) ?. split ( "," ) . filter ( Boolean ) ?? [ ] ;
16
16
17
- const api = new Hono ( ) ;
18
17
const logger = new Logger ( ) ;
19
18
20
- api . use ( async ( c , next ) => {
21
- const apiKey = c . req . header ( "X-API-Key" ) ;
19
+ const api = new Hono ( )
20
+ . use ( async ( c , next ) => {
21
+ const apiKey = c . req . header ( "X-API-Key" ) ;
22
22
23
- if ( ! apiKey ) {
24
- await logger . apiAccess ( c , "Unauthorized" , true , apiKey ) ;
25
- throw new HTTPException ( 401 , { message : "Unauthorized" } ) ;
26
- }
23
+ if ( ! apiKey ) {
24
+ await logger . apiAccess ( c , "Unauthorized" , true , apiKey ) ;
25
+ throw new HTTPException ( 401 , { message : "Unauthorized" } ) ;
26
+ }
27
27
28
- if ( ! apiKeys . includes ( apiKey ) ) {
29
- await logger . apiAccess ( c , "Forbidden" , true , apiKey ) ;
30
- throw new HTTPException ( 403 , { message : "Forbidden" } ) ;
31
- }
28
+ if ( ! apiKeys . includes ( apiKey ) ) {
29
+ await logger . apiAccess ( c , "Forbidden" , true , apiKey ) ;
30
+ throw new HTTPException ( 403 , { message : "Forbidden" } ) ;
31
+ }
32
32
33
- await logger . apiAccess ( c , "Accessed" , false , apiKey ) ;
34
- await next ( ) ;
35
- } ) ;
36
-
37
- api . get ( "/all" , getAllItemsController ) ;
38
- api . get ( "/items/:param" , getItemController ) ;
39
- api . put (
40
- "/items/:param" ,
41
- zValidator (
42
- "json" ,
43
- z . object ( {
44
- description : z . string ( ) . optional ( ) ,
45
- url : z . string ( ) . url ( ) ,
46
- count : z . number ( ) . optional ( ) ,
47
- } ) ,
48
- ) ,
49
- ( c ) => {
50
- const { description, url, count } = c . req . valid ( "json" ) ;
51
- return putItemController ( c , description , url , count ) ;
52
- } ,
53
- ) ;
54
- api . patch (
55
- "/items/:param" ,
56
- zValidator (
57
- "json" ,
58
- z . object ( {
59
- description : z . string ( ) . optional ( ) ,
60
- url : z . string ( ) . url ( ) . optional ( ) ,
61
- count : z . number ( ) . optional ( ) ,
62
- unavailable : z . boolean ( ) . optional ( ) ,
63
- } ) ,
64
- ) ,
65
- ( c ) => {
66
- const { description, url, count, unavailable } = c . req . valid ( "json" ) ;
67
- return patchItemController ( c , description , url , count , unavailable ) ;
68
- } ,
69
- ) ;
70
- api . delete ( "/items/:param" , deleteItemController ) ;
33
+ await logger . apiAccess ( c , "Accessed" , false , apiKey ) ;
34
+ await next ( ) ;
35
+ } )
36
+ . get ( "/all" , getAllItemsController )
37
+ . get ( "/items/:param" , getItemController )
38
+ . put (
39
+ "/items/:param" ,
40
+ zValidator (
41
+ "json" ,
42
+ z . object ( {
43
+ description : z . string ( ) . optional ( ) ,
44
+ url : z . string ( ) . url ( ) ,
45
+ count : z . number ( ) . optional ( ) ,
46
+ } ) ,
47
+ ) ,
48
+ ( c ) => {
49
+ const { description, url, count } = c . req . valid ( "json" ) ;
50
+ return putItemController ( c , description , url , count ) ;
51
+ } ,
52
+ )
53
+ . patch (
54
+ "/items/:param" ,
55
+ zValidator (
56
+ "json" ,
57
+ z . object ( {
58
+ description : z . string ( ) . optional ( ) ,
59
+ url : z . string ( ) . url ( ) . optional ( ) ,
60
+ count : z . number ( ) . optional ( ) ,
61
+ unavailable : z . boolean ( ) . optional ( ) ,
62
+ } ) ,
63
+ ) ,
64
+ ( c ) => {
65
+ const { description, url, count, unavailable } = c . req . valid ( "json" ) ;
66
+ return patchItemController ( c , description , url , count , unavailable ) ;
67
+ } ,
68
+ )
69
+ . delete ( "/items/:param" , deleteItemController ) ;
71
70
72
71
export default api ;
0 commit comments