From d005e0d07a66b767023560fec02842d56f7b0ca8 Mon Sep 17 00:00:00 2001 From: gulatichayan Date: Sun, 25 Aug 2024 00:10:58 +0800 Subject: [PATCH] Fix issue - handler is not a constructor - when using export default controllerFunc TypeError: handler is not a constructor observed when using export default controllerFunc; --- src/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 30586f6..1c7fe2a 100644 --- a/src/index.js +++ b/src/index.js @@ -76,7 +76,14 @@ const mapRoutes = (routes, pathToController, middlewareGenerals = []) => { } catch (err) { require('@babel/register'); handler = require(`${myPathToController}${controller}`).default; - contr = new handler(); + + isConstructable = isConstructor(handler); + + if (isConstructable) { + contr = new handler(); + } else { + contr = handler(); + } } router.route(myPath)[requestMethod](middlewares, contr[controllerMethod]);