From 3954843a75d4f4ef94feb65ccf9448a63f759cba Mon Sep 17 00:00:00 2001 From: Zac Lovoy Date: Thu, 25 Sep 2025 15:59:26 -0700 Subject: [PATCH 1/2] fix(js/testapps/express): Fixed express testapp endpoints --- js/testapps/express/src/index.ts | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/js/testapps/express/src/index.ts b/js/testapps/express/src/index.ts index 993e85af4a..50461eaa92 100644 --- a/js/testapps/express/src/index.ts +++ b/js/testapps/express/src/index.ts @@ -39,16 +39,18 @@ const ai = genkit({ ], }); +const selectedModel = gemini15Flash; + export const jokeFlow = ai.defineFlow( { name: 'jokeFlow', inputSchema: z.string(), outputSchema: z.string() }, async (subject, { context, sendChunk }) => { - if (context!.auth!.username != 'Ali Baba') { - throw new UserFacingError('PERMISSION_DENIED', context!.auth!.username!); + if (context?.auth?.username && context.auth.username !== 'Ali Baba') { + throw new UserFacingError('PERMISSION_DENIED', context.auth.username); } return await ai.run('call-llm', async () => { const llmResponse = await ai.generate({ prompt: `tell me long joke about ${subject}`, - model: gemini15Flash, + model: selectedModel, config: { temperature: 1, }, @@ -96,18 +98,13 @@ const acls: Record = { jokeFlow: 'Ali Baba', }; -// curl http://localhost:5000/jokeFlow?stream=true -d '{"data": "banana"}' -H "content-type: application/json" -H "authorization: open sesame" -ai.flows.forEach((f) => { - app.post( - `/${f.name}`, - expressHandler(f, { contextProvider: auth(acls[f.name]) }) - ); -}); +// curl http://localhost:8080/jokeFlow?stream=true -d '{"data": "banana"}' -H "content-type: application/json" -H "authorization: open sesame" +app.post('/jokeFlow', expressHandler(jokeFlow, { contextProvider: auth(acls['jokeFlow']) })); -// curl http://localhost:5000/jokeHandler?stream=true -d '{"data": "banana"}' -H "content-type: application/json" +// curl http://localhost:8080/jokeHandler?stream=true -d '{"data": "banana"}' -H "content-type: application/json" app.post('/jokeHandler', expressHandler(jokeFlow)); -// curl http://localhost:5000/jokeWithFlow?subject=banana +// curl http://localhost:8080/jokeWithFlow?subject=banana app.get('/jokeWithFlow', async (req: Request, res: Response) => { const subject = req.query['subject']?.toString(); if (!subject) { @@ -117,7 +114,7 @@ app.get('/jokeWithFlow', async (req: Request, res: Response) => { res.send(await jokeFlow(subject)); }); -// curl http://localhost:5000/jokeStream?subject=banana +// curl http://localhost:8080/jokeStream?subject=banana app.get('/jokeStream', async (req: Request, res: Response) => { const subject = req.query['subject']?.toString(); if (!subject) { @@ -131,7 +128,7 @@ app.get('/jokeStream', async (req: Request, res: Response) => { }); await ai.generate({ prompt: `Tell me a long joke about ${subject}`, - model: gemini15Flash, + model: selectedModel, config: { temperature: 1, }, @@ -143,7 +140,7 @@ app.get('/jokeStream', async (req: Request, res: Response) => { res.end(); }); -const port = process.env.PORT || 5000; +const port = process.env.PORT || 8080; app.listen(port, () => { console.log(`Example app listening on port ${port}`); }); From c0a6b95b5cf4af2b8faf500c50660bf654b28d23 Mon Sep 17 00:00:00 2001 From: Zac Lovoy Date: Thu, 25 Sep 2025 16:11:40 -0700 Subject: [PATCH 2/2] fix(js/testapps/express): Fixed express testapp endpoints --- js/testapps/express/src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/testapps/express/src/index.ts b/js/testapps/express/src/index.ts index 50461eaa92..cf2e521c66 100644 --- a/js/testapps/express/src/index.ts +++ b/js/testapps/express/src/index.ts @@ -99,7 +99,10 @@ const acls: Record = { }; // curl http://localhost:8080/jokeFlow?stream=true -d '{"data": "banana"}' -H "content-type: application/json" -H "authorization: open sesame" -app.post('/jokeFlow', expressHandler(jokeFlow, { contextProvider: auth(acls['jokeFlow']) })); +app.post( + '/jokeFlow', + expressHandler(jokeFlow, { contextProvider: auth(acls['jokeFlow']) }) +); // curl http://localhost:8080/jokeHandler?stream=true -d '{"data": "banana"}' -H "content-type: application/json" app.post('/jokeHandler', expressHandler(jokeFlow));