Giter Club home page Giter Club logo

Comments (4)

Usbac avatar Usbac commented on May 29, 2024 2

Hello @sephentos, thank you for pointing out that improvement, it has been done in the new version 4.1.0!

Now middleware closures can take the response object as third argument.

Just remember to run a composer update. πŸ˜„

from wolff.

Usbac avatar Usbac commented on May 29, 2024 2

You're welcome @sephentos! :)

The code routes have a higher hierarchy than the middlewares, and the maintenance mode does not take into account the middlewares, sorry about that detail.

I have been thinking about changing it but such change would break backward compatibility so for now it's reserved for the version 5.0.

from wolff.

sephentos avatar sephentos commented on May 29, 2024 1

Alright! Thanks for the reply.
(Also being already hyped for 5.0, really loving your work 😊)

from wolff.

sephentos avatar sephentos commented on May 29, 2024

Hey @Usbac !
Thank you very much for the very quick fix! :)

Just one more little thing (really not important!): The middleware does not intervene with Route::code or Maintenance::set when making them listen to *.
See example:

Middleware::before('*', function($req, $next, $res) {
    $res->setHeader('Content-Type', 'application/json');
});

// works fine, content-type is application/json
Route::get('/', function ($req,$res) {
    $res->writeJson([ 'test' => 'test']);
});

// does not work, middleware not being applied
Route::code(404, function ($req,$res) {
    $res->writeJson([ 'test' => 'test']);
});

// does not work, middleware not being applied
Maintenance::set(function($req, $res) {
    $res->writeJson([ 'test' => 'test']);
});

To be fair, thats a very simple example in which I could copypaste setHeader to both, but I was thinking about adding more stuff into the middleware later.

I guess that it would not be so easy to set the routing (Middleware::before('*') of the middleware for a 404 or maintenance. Would it otherwise be possible to call the middleware within the 404 / maintenance functions by some way?

from wolff.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.