feat: Convert routes folder to the js files

This commit is contained in:
Faruk AYDIN
2023-12-28 13:22:23 +01:00
parent aceebba99a
commit 9d1aa9e59a
4 changed files with 37 additions and 33 deletions

View File

@@ -0,0 +1,52 @@
import express, { Router } from 'express';
import multer from 'multer';
import appConfig from '../config/app';
import webhookHandlerByFlowId from '../controllers/webhooks/handler-by-flow-id';
import webhookHandlerByConnectionIdAndRefValue from '../controllers/webhooks/handler-by-connection-id-and-ref-value';
const router = Router();
const upload = multer();
router.use(upload.none());
router.use(
express.text({
limit: appConfig.requestBodySizeLimit,
verify(req, res, buf) {
req.rawBody = buf;
},
})
);
const exposeError = (handler) => async (req, res, next) => {
try {
await handler(req, res, next);
} catch (err) {
next(err);
}
};
function createRouteHandler(path, handler) {
const wrappedHandler = exposeError(handler);
router
.route(path)
.get(wrappedHandler)
.put(wrappedHandler)
.patch(wrappedHandler)
.post(wrappedHandler);
}
createRouteHandler(
'/connections/:connectionId/:refValue',
webhookHandlerByConnectionIdAndRefValue
);
createRouteHandler(
'/connections/:connectionId',
webhookHandlerByConnectionIdAndRefValue
);
createRouteHandler('/flows/:flowId', webhookHandlerByFlowId);
createRouteHandler('/:flowId', webhookHandlerByFlowId);
export default router;