Skip to content

Commit 6691178

Browse files
committed
refactor: frame markup via module
Previously done via request.
1 parent e18595a commit 6691178

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

api/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const respondWithFrame = async (frameName, frameSrc, payload) => {
6262
image: ``,
6363
buttons: frameSrc.buttons ? buildButtons(frameSrc.buttons) : [],
6464
inputs: frameSrc.inputs ? buildInputs(frameSrc.inputs) : [],
65-
postURL: `${host}?frame=${frameName}`
65+
postURL: `${host}/?frame=${frameName}`
6666
}
6767

6868
const frameData = {

api/og-image.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import satori from "satori";
22
import sharp from "sharp";
33
import { html } from "satori-html";
44
import fonts from "../src/fonts";
5+
import frames from "../src/frames";
6+
import { URLSearchParamsToObject } from '../modules/utils';
57

68
export default async (req, context) => {
7-
const inboundUrl = new URL(req.url);
8-
const host = process.env.URL;
9-
10-
const frameUrl = `${host}/frame?${inboundUrl.searchParams}`;
11-
const htmlResponse = await fetch(frameUrl);
12-
const markup = await htmlResponse.text();
9+
const url = new URL(req.url);
10+
const frameData = URLSearchParamsToObject(url.searchParams);
11+
const frameSrc = frames[frameData.name];
12+
const markup = await frameSrc.build(frameData);
1313

1414
const svg = await satori(
1515
html(markup),
@@ -26,7 +26,10 @@ export default async (req, context) => {
2626
return new Response(response,
2727
{
2828
status: 200,
29-
headers: { 'Content-Type': 'image/png' }
29+
headers: {
30+
'Content-Type': 'image/png',
31+
'Cache-Control': 'public, max-age=31536000'
32+
}
3033
}
3134
);
3235
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "simplest-frame",
33
"type": "module",
4-
"version": "0.6.0",
4+
"version": "0.6.1",
55
"dependencies": {
66
"@netlify/blobs": "^6.4.2",
77
"dompurify": "^3.0.8",

0 commit comments

Comments
 (0)