Skip to content

Commit a1ac37e

Browse files
committed
chore: Updated README
1 parent 4d6ae93 commit a1ac37e

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

README.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -111,52 +111,52 @@ import { abi } from "../utils/contract";
111111
import { pinata } from "../utils/pinata";
112112

113113
export 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

Comments
 (0)