Skip to content

Commit

Permalink
fix: routes
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Feb 8, 2024
1 parent 9383408 commit 07d0b97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 10 additions & 0 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ app.frame('/', ({ status }) => {
}
})

app.frame('/no-intents', () => {
return {
image: (
<div style={{ backgroundColor: 'red', width: '100%', height: '100%' }}>
foo
</div>
),
}
})

export default {
port: 3001,
fetch: app.fetch,
Expand Down
13 changes: 7 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type FrameContext = {

type FrameReturnType = {
image: JSX.Element
intents: JSX.Element
intents?: JSX.Element
}

export class Framework extends Hono {
Expand All @@ -44,7 +44,7 @@ export class Framework extends Hono {
handler: (c: FrameContext) => FrameReturnType | Promise<FrameReturnType>,
) {
// Frame Route (implements GET & POST).
this.use(async (c) => {
this.use(path, async (c) => {
const context = await getFrameContext(c)
const { intents } = await handler(context)
const serializedContext = encodeURIComponent(JSON.stringify(context))
Expand All @@ -65,14 +65,14 @@ export class Framework extends Hono {
)}/image?context=${serializedContext}`}
/>
<meta property="fc:frame:post_url" content={context.url} />
{parseIntents(intents)}
{intents ? parseIntents(intents) : null}
</head>
</html>,
)
})

// OG Image Route
this.get('image', async (c) => {
this.get(`${parseUrl(path)}/image`, async (c) => {
const { context } = c.req.query()
const parsedContext = JSON.parse(
decodeURIComponent(context),
Expand All @@ -83,7 +83,7 @@ export class Framework extends Hono {

// Frame Preview Routes
this.use(
'preview',
`${parseUrl(path)}/preview`,
jsxRenderer(
({ children }) => {
return (
Expand Down Expand Up @@ -224,8 +224,9 @@ export class Framework extends Hono {
)
})

// TODO: fix this – does it work?
// Package up the above routes into `path`.
this.route(path, this)
// this.route(path, this)
}
}

Expand Down

0 comments on commit 07d0b97

Please sign in to comment.