nathggns / Scaffold

Lightweight PHP API Framework
Other
8 stars 2 forks source link

Support for middlewares on the Router. #129

Open nathggns opened 11 years ago

nathggns commented 11 years ago

You should be able to assign one or more "middlewares" that act before the controller, and can actually stop the controller from being called.

This can be used for authentication, for example.

I'd like to merge this into #128, so we can add a middleware to prevent CONSOLE requests via HTTP.

What do you think?

ClaudioAlbertin commented 11 years ago

The router would have to be a middleware as well. This requires a little rewrite of our request system so far. We need to discuss more specific details.

nathggns commented 11 years ago

How so? :S — Nathaniel Higgins http://nath.is

On Sat, Jun 8, 2013 at 7:15 PM, Claudio Albertin notifications@github.com wrote:

The router would have to be a middleware as well. This requires a little rewrite of our request system so far. We need to discuss more specific details.

Reply to this email directly or view it on GitHub: https://github.com/Scaffold/Scaffold/issues/129#issuecomment-19152958

ClaudioAlbertin commented 11 years ago

A lot like middleware works with connect.js.

nathggns commented 11 years ago

I haven't used connect.js… would you like to explain?  — Nathaniel Higgins http://nath.is

On Sat, Jun 8, 2013 at 8:29 PM, Claudio Albertin notifications@github.com wrote:

A lot like middleware works with connect.js.

Reply to this email directly or view it on GitHub: https://github.com/Scaffold/Scaffold/issues/129#issuecomment-19154089

ClaudioAlbertin commented 11 years ago

One middleware after the other is called and can register an error in which case the next middleware can decide whether it wants to handle the request or just pass on the error. Once the pointer has reached the end of the middleware queue, ... well, the request is considered handled. This is also a fancy way to implement automatically sending the request.

nathggns commented 11 years ago

I'd rather a less drastic change to be honest. Ability to hook a callback that has access to the request object, and can decide to stop the request and throw an error if needs be.

On 8 June 2013 20:40, Claudio Albertin notifications@github.com wrote:

One middleware after the other is called and can register an error in which case the next middleware can decide whether it wants to handle the request or just pass on the error. Once the pointer has reached the end of the middleware queue, ... well, the request is considered handled. This is also a fancy way to implement automatically sending the request.

— Reply to this email directly or view it on GitHubhttps://github.com/Scaffold/Scaffold/issues/129#issuecomment-19154242 .

Nathaniel Higgins http://nath.is @nathggns http://twitter.com/nathggns