Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
fahreddinozcan committed Nov 7, 2024
1 parent 494df70 commit d557669
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions examples/express/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,42 @@ const app = express();
app.use(express.json());

const someWork = (input: string) => {
return `message: '${JSON.stringify(input)}'`
return `processed: '${JSON.stringify(input)}'`
}

app.use('/workflow', serve<{ message: string }>(async (context) => {
const input = context.requestPayload
console.log("input", input);

const result1 = await context.run('step1', async () => {
const output = someWork(input.message)
console.log('step 1 input', input, 'output', output)
return output
})

const { body } = await context.call("get-data", {
url: `${process.env.UPSTASH_WORKFLOW_URL}/get-data`,
method: "POST",
body: { message: result1 }
})

await context.run('step2', async () => {
const output = someWork(result1)
const { message } = (body as { message: string })
const output = someWork(message)
console.log('step 2 input', result1, 'output', output)
return output
})
}));

app.post("/get-data", (req, res) => {
// Log the incoming request body for debugging
console.log('get-data received:', req.body);

// Send back the message
res.json(req.body);
});



app.listen(3001, () => {
console.log('Server running on port 3001');
});

0 comments on commit d557669

Please sign in to comment.