From 07d0b97159ceca442b10e8d0d5e63944941ea992 Mon Sep 17 00:00:00 2001 From: "moxey.eth" Date: Thu, 8 Feb 2024 15:46:40 +1100 Subject: [PATCH] fix: routes --- example/src/index.tsx | 10 ++++++++++ src/index.tsx | 13 +++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/example/src/index.tsx b/example/src/index.tsx index c5450413..808c2df8 100644 --- a/example/src/index.tsx +++ b/example/src/index.tsx @@ -48,6 +48,16 @@ app.frame('/', ({ status }) => { } }) +app.frame('/no-intents', () => { + return { + image: ( +
+ foo +
+ ), + } +}) + export default { port: 3001, fetch: app.fetch, diff --git a/src/index.tsx b/src/index.tsx index 207bb379..1a74b0c3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -35,7 +35,7 @@ type FrameContext = { type FrameReturnType = { image: JSX.Element - intents: JSX.Element + intents?: JSX.Element } export class Framework extends Hono { @@ -44,7 +44,7 @@ export class Framework extends Hono { handler: (c: FrameContext) => FrameReturnType | Promise, ) { // 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)) @@ -65,14 +65,14 @@ export class Framework extends Hono { )}/image?context=${serializedContext}`} /> - {parseIntents(intents)} + {intents ? parseIntents(intents) : null} , ) }) // 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), @@ -83,7 +83,7 @@ export class Framework extends Hono { // Frame Preview Routes this.use( - 'preview', + `${parseUrl(path)}/preview`, jsxRenderer( ({ children }) => { return ( @@ -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) } }