@@ -111,52 +111,52 @@ import { abi } from "../utils/contract";
111111import { pinata } from " ../utils/pinata" ;
112112
113113export default {
114- async fetch(
115- request : Request ,
116- env : Env ,
117- ctx : ExecutionContext ,
118- ): Promise <Response > {
119- try {
120- const publicClient = createPublicClient ({
121- chain: baseSepolia ,
122- transport: http (),
123- });
124-
125- const cid = await publicClient .readContract ({
126- address: " 0x81FBD1886121f8575734808959DF808D19De170D" ,
127- abi: abi ,
128- functionName: " getMapping" ,
129- });
130-
131- if (! cid ) {
132- throw new Error (` Failed to fetch latest state: ${cid } ` );
133- }
134-
135- const url = await pinata .gateways .convert (cid as string );
136-
137- const response = await fetch (url );
138-
139- if (! response .ok ) {
140- throw new Error (` Failed to fetch from CDN: ${response .statusText } ` );
141- }
142-
143- const contentType = response .headers .get (" content-type" );
144-
145- return new Response (response .body , {
146- status: 200 ,
147- headers: {
148- " Content-Type" : contentType || " text/html" ,
149- " Cache-Control" : " public, max-age=3600" ,
150- },
151- });
152- } catch (error ) {
153- console .error (" Error:" , error );
154- return new Response (` Error: ${error } ` , {
155- status: 500 ,
156- headers: { " Content-Type" : " text/plain" },
157- });
158- }
159- },
114+ async fetch(
115+ request : Request ,
116+ env : Env ,
117+ ctx : ExecutionContext ,
118+ ): Promise <Response > {
119+ try {
120+ const publicClient = createPublicClient ({
121+ chain: baseSepolia ,
122+ transport: http (),
123+ });
124+
125+ const cid = await publicClient .readContract ({
126+ address: " 0x81FBD1886121f8575734808959DF808D19De170D" ,
127+ abi: abi ,
128+ functionName: " getMapping" ,
129+ });
130+
131+ if (! cid ) {
132+ throw new Error (` Failed to fetch latest state: ${cid } ` );
133+ }
134+
135+ const url = await pinata .gateways .convert (cid as string );
136+
137+ const response = await fetch (url );
138+
139+ if (! response .ok ) {
140+ throw new Error (` Failed to fetch from CDN: ${response .statusText } ` );
141+ }
142+
143+ const contentType = response .headers .get (" content-type" );
144+
145+ return new Response (response .body , {
146+ status: 200 ,
147+ headers: {
148+ " Content-Type" : contentType || " text/html" ,
149+ " Cache-Control" : " public, max-age=3600" ,
150+ },
151+ });
152+ } catch (error ) {
153+ console .error (" Error:" , error );
154+ return new Response (` Error: ${error } ` , {
155+ status: 500 ,
156+ headers: { " Content-Type" : " text/plain" },
157+ });
158+ }
159+ },
160160} satisfies ExportedHandler <Env >;
161161```
162162
0 commit comments