jaysylvester / citizen

Node.js MVC web application framework. Includes routing, serving, caching, session management, and other helpful tools.
MIT License
100 stars 7 forks source link

JSON requests should return the local context for the entire controller chain #127

Closed jaysylvester closed 4 months ago

jaysylvester commented 5 months ago

JSON requests currently return the local context of only the last controller in the chain. If the layout is enabled, it ends up being the layout context, which is likely not the desired result. Relying on /direct/true isn't entirely intuitive, plus it only returns the requested controller's local context.

Since the local context is stored within each chain controller object, it should be easy enough to loop over it after the last controller and return something like the following:

{
  "index": {
    "hippity": "dippity",
    "include": {
      "formDemo": {
        "foo": "bar"
      }
    }
  },
  "layout": {
    "browsersyncEnabled": true,
    "include": {
      "header": {
        "foo": "bar"
      },
      "footer": {
        "copyrightDate": 2024
      },
      "head": {
        "metaData": {
          "title": "Model Citizen: A citizen framework demo",
          "description": "This view is rendered by the index controller.",
          "keywords": "citizen, node, node.js"
        }
      }
    }
  }
}