feat: add multithreaded factorial endpoint to express example
[poolifier.git] / examples / typescript / http-server-pool / express / src / main.ts
index 02e139399259b4272b958ba41bb9420aef796f3c..b7a713e03ae4798f5aa48b9bf545ab258c49d6e2 100644 (file)
@@ -27,6 +27,16 @@ expressApp.all('/api/echo', (req: Request, res: Response) => {
     .catch(emptyFunction)
 })
 
+expressApp.get('/api/factorial/:number', (req: Request, res: Response) => {
+  const { number } = req.params
+  requestHandlerPool
+    .execute({ body: { number } }, 'factorial')
+    .then(response => {
+      return res.send(response.body).end()
+    })
+    .catch(emptyFunction)
+})
+
 try {
   expressApp.listen(port, () => {
     console.info(