Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a middleware to protect ignition routes #93

Merged
merged 3 commits into from
Sep 5, 2019

Conversation

mpociot
Copy link
Contributor

@mpociot mpociot commented Sep 4, 2019

By always registering our routes we avoid issues like #87
The middleware then takes care of choosing whether or not the route should be reachable.

Copy link
Collaborator

@freekmurze freekmurze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

You could opt to add a test for that middleware.

use Closure;
use Illuminate\Http\Request;

class IgnitionEnabled
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a test for this middleware, so we're 100% sure it works correctly.


Route::get('scripts/{script}', ScriptController::class);
Route::get('styles/{style}', StyleController::class);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't routes be registered in boot()? That goes for almost every service in the IoC container - don't resolve them until all other service providers had a chance to modify / extend / swap them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in our case this would introduce some issues if an exception would occur in a service providers boot method prior to Ignition.
Because our whoops handler would already be registered, but the routes would not. That's why we are registering the routes here too.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about $this->app->resolving('router', function () { ... });?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marcel and I discussed this. We don't think it is necessary. The router will always have been registered when our provider gets called.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is not so much your provider (although you shouldn't rely on the provider ordering). You also should be a good citizen and allow other packages to swap out the router / extend it in some way, before you access it.

That's at least 50% of the point of the IoC container and contracts, as I understand them. 😉

@freekmurze freekmurze merged commit 6e5d134 into master Sep 5, 2019
@freekmurze freekmurze deleted the use-middleware-for-ignition-routes branch September 5, 2019 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants