@@ -101,32 +101,28 @@ export default {
101101import { createConnection } from ' mysql2/promise' ;
102102
103103export default {
104- async fetch(request , env , ctx ): Promise <Response > {
104+ async fetch(request , env , ctx ): Promise <Response > {
105105 const connection = await createConnection ({
106106 host: env .DB_HOST ,
107107 user: env .DB_USER ,
108108 password: env .DB_PASSWORD ,
109109 database: env .DB_NAME ,
110110 port: env .DB_PORT
111111
112- // This is needed to use mysql2 with Workers
112+ // This is needed to use mysql2 with Workers
113113 // This configures mysql2 to use static parsing instead of eval() parsing (not available on Workers)
114114 disableEval : true
115+ });
115116
116- } );
117+ const [results, fields] = await connection . query ( ' SHOW tables; ' );
117118
118- const [results, fields] = await connection .query (
119- ' SHOW tables;'
120- );
121-
122- return new Response (JSON .stringify ({ results , fields }), {
123- headers: {
124- ' Content-Type' : ' application/json' ,
125- ' Access-Control-Allow-Origin' : ' \* ' ,
126- },
127- });
128- },
129- } satisfies ExportedHandler <Env >;
119+ return new Response (JSON .stringify ({ results , fields }), {
120+ headers: {
121+ ' Content-Type' : ' application/json' ,
122+ ' Access-Control-Allow-Origin' : ' \* ' ,
123+ },
124+ });
125+ }} satisfies ExportedHandler <Env >;
130126
131127````
132128
0 commit comments