Providing an Async Handler Function to Express
Open your lib/bundle.js and add the following inside the module.exports function, after the bundle-creation API you added previously.
â | â/**â |
â | â * Retrieve a given bundle.â |
â | â * curl http://<host>:<port>/api/bundle/<id>â |
â | â */â |
â | app.âgetâ(â'/api/bundle/:id'â, âasyncâ (req, res) => { |
â | âconstâ options = { |
â | url: â`â${url}â/â${req.params.id}â`â, |
â | json: âtrueâ, |
â | }; |
â | âtryâ { |
â | âconstâ esResBody = âawaitâ rp(options); |
â | res.status(200).json(esResBody); |
â | } âcatchâ (esResErr) { |
â | res.status(esResErr.statusCode || 502).json(esResErr.error); |
â | } |
â | }); |
This code block ...
Get Node.js 8 the Right Way now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.