@triophore/falconjs 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/falcon.js +31 -12
  2. package/package.json +1 -1
package/falcon.js CHANGED
@@ -666,24 +666,43 @@ class Falcon {
666
666
  try {
667
667
  const routeModule = require(filePath);
668
668
 
669
- // Flexible export: can be a handler function, or an object with handler/options
670
- // OR legacy support: function that takes context (but we need to manually register)
669
+ let handler, options = {}, finalMethod = method, finalPath = routePath;
671
670
 
672
- let handler, options = {};
671
+ // NEW PATTERN: module.exports.route = async function(context) { return { ... } }
672
+ if (routeModule.route && typeof routeModule.route === 'function') {
673
+ const routeConfig = await routeModule.route(this.CONTEXT);
673
674
 
674
- if (typeof routeModule === 'function') {
675
- // Assume it's a handler(request, h)
675
+ if (!routeConfig) {
676
+ this.CONTEXT["logger"].warn(`Skipping ${relativePath}: route() returned null/undefined`);
677
+ continue;
678
+ }
679
+
680
+ // Extract handler and options from returned config
681
+ handler = routeConfig.handler;
682
+ options = routeConfig.options || {};
683
+
684
+ // Allow optional method/path override from return value
685
+ if (routeConfig.method) {
686
+ finalMethod = routeConfig.method;
687
+ this.CONTEXT["logger"].debug(`Method overridden to ${finalMethod} for ${relativePath}`);
688
+ }
689
+ if (routeConfig.path) {
690
+ finalPath = routeConfig.path;
691
+ this.CONTEXT["logger"].debug(`Path overridden to ${finalPath} for ${relativePath}`);
692
+ }
693
+ }
694
+ // LEGACY PATTERN: Direct handler function export
695
+ else if (typeof routeModule === 'function') {
676
696
  handler = routeModule;
677
- } else if (typeof routeModule === 'object') {
697
+ }
698
+ // LEGACY PATTERN: Object with handler/options
699
+ else if (typeof routeModule === 'object') {
678
700
  if (routeModule.handler) handler = routeModule.handler;
679
701
  if (routeModule.options) options = routeModule.options;
680
-
681
- // If user exported .route function (legacy), we can't really use it easily with new params
682
- // unless we assume they migrated. We'll stick to handler/options pattern for new files.
683
702
  }
684
703
 
685
704
  if (!handler) {
686
- this.CONTEXT["logger"].warn(`Skipping ${relativePath}: No handler exported`);
705
+ this.CONTEXT["logger"].warn(`Skipping ${relativePath}: No handler found`);
687
706
  continue;
688
707
  }
689
708
 
@@ -705,8 +724,8 @@ class Falcon {
705
724
 
706
725
  // Register the route
707
726
  this.httpServer.route({
708
- method: method,
709
- path: routePath,
727
+ method: finalMethod,
728
+ path: finalPath,
710
729
  handler: handler,
711
730
  options: {
712
731
  tags: [tag],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triophore/falconjs",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "simple server framework for nodejs",
5
5
  "main": "index.js",
6
6
  "scripts": {