Kainoa
Kainoa
CDCloudflare Developers
Created by Kainoa on 10/25/2024 in #pages-help
Unable to run async logic in page function?
Even though this server is practically dead, I figured it out. Here's the solution if anyone searches for this:
import React from "react";
import { ImageResponse } from "workers-og"; // maintained library

export const onRequest: PagesFunction = async ({
request,
next,
env,
waitUntil,
}) => {
const url = new URL(request.url);

// await whatever logic

function component({ apiData }: { apiData: Market }) {
return (
<div> //...
)};

return new ImageResponse(component({ apiData }), {
emoji: "twemoji",

});
import React from "react";
import { ImageResponse } from "workers-og"; // maintained library

export const onRequest: PagesFunction = async ({
request,
next,
env,
waitUntil,
}) => {
const url = new URL(request.url);

// await whatever logic

function component({ apiData }: { apiData: Market }) {
return (
<div> //...
)};

return new ImageResponse(component({ apiData }), {
emoji: "twemoji",

});
2 replies