diff --git a/functions/[id].ts b/functions/[id].ts new file mode 100644 index 0000000..cd568d4 --- /dev/null +++ b/functions/[id].ts @@ -0,0 +1,31 @@ +interface Env {} + +export const onRequest: PagesFunction = async context => { + const id = context.params.id as string; + + const next = await context.next(); + try { + const rsp = await fetch(`http://nostr.api.v0l.io/api/v1/opengraph/${id}?canonical=${encodeURIComponent("https://zap.stream/%s")}`, { + method: "POST", + body: await next.arrayBuffer(), + headers: { + "user-agent": "zap.stream/1.0 (https://zap.stream)", + "content-type": "text/html", + "accept": "text/html" + }, + }); + if (rsp.ok) { + const body = await rsp.text(); + if (body.length > 0) { + return new Response(body, { + headers: { + "content-type": "text/html", + }, + }); + } + } + } catch { + // ignore + } + return next; +}; diff --git a/functions/tsconfig.json b/functions/tsconfig.json new file mode 100644 index 0000000..da95421 --- /dev/null +++ b/functions/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "lib": ["esnext"], + "types": ["@cloudflare/workers-types"] + } +} diff --git a/package.json b/package.json index 1860610..507376d 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ ] }, "devDependencies": { + "@cloudflare/workers-types": "^4.20231218.0", "@formatjs/cli": "^6.1.3", "@formatjs/ts-transformer": "^3.13.3", "@testing-library/dom": "^9.3.1", diff --git a/yarn.lock b/yarn.lock index 8b74c23..f7915af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1556,6 +1556,13 @@ __metadata: languageName: node linkType: hard +"@cloudflare/workers-types@npm:^4.20231218.0": + version: 4.20231218.0 + resolution: "@cloudflare/workers-types@npm:4.20231218.0" + checksum: b7e50a76ee8e9d662227bbb74798b93b6102acc224f1071a9c99a9adb419ad0b3bdabf7561e7e1b4a320a6a4616badeecdfb1848fbdaada197c7b37d845b8774 + languageName: node + linkType: hard + "@emoji-mart/data@npm:^1.1.2": version: 1.1.2 resolution: "@emoji-mart/data@npm:1.1.2" @@ -7792,6 +7799,7 @@ __metadata: version: 0.0.0-use.local resolution: "stream_ui@workspace:." dependencies: + "@cloudflare/workers-types": ^4.20231218.0 "@emoji-mart/data": ^1.1.2 "@emoji-mart/react": ^1.1.1 "@formatjs/cli": ^6.1.3