fastlane
Version:
Fastlane is a fast and flexible API framework for Node.js. It automatically creates Express routes from your project's file structure, making it easy to build APIs quickly and efficiently.
26 lines • 768 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.methodHandler = methodHandler;
function methodHandler(fn) {
return async (req, res, next) => {
try {
const data = await fn(req, res);
if (typeof data === "undefined") {
res.json({ success: true });
}
else if (Array.isArray(data)) {
res.json({ data, success: true });
}
else if (typeof data === 'object') {
res.json({ ...data, success: true });
}
else {
res.json({ data, success: true });
}
}
catch (err) {
next(err);
}
};
}
//# sourceMappingURL=handler.js.map