Skip to content
New issue

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

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

Already on GitHub? # to your account

Feature - Disable Frontend... #78

Merged
merged 4 commits into from
Apr 20, 2018

Conversation

Raistlfiren
Copy link
Collaborator

Added the ability to disable the frontend through a configuration value and just show a blank page.

@Raistlfiren Raistlfiren requested a review from xiaohutai March 30, 2018 23:04
);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you un-nest this. Early returns are far better for human reading of logical intent, and there is rarely a time where an if statement inside another is valid.

@@ -63,11 +65,41 @@ public static function getSubscribedEvents()
KernelEvents::EXCEPTION => [
['error', 515],
],
KernelEvents::CONTROLLER => [
['disableFrontend', -1025]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is massively high (late in terms of priority, but not the point 😛 ). Does it really need to be?

public function disableFrontend(FilterControllerEvent $event)
{
$request = $event->getRequest();
//$response = $event->getResponse();
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove commented code


$container = $this->getContainer();

//Get route name
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment serves no purpose 😉

if ($container['jsonapi.config']->isDisableFrontend()) {
//Only disable frontend routes, don't disable json routes
if (strpos($routeName, 'jsonapi') === false) {
$event->stopPropagation();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed. You're setting a non-null value below

$event->setController(
function() {
return new Response('', 200);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You're better off throwing a HttpException here with a 403 or similar. This is just a nightmare to debug if for some reason it is being unexpectedly called … the Samuel L. Jackson Law of Assumption in full flight.

@Raistlfiren
Copy link
Collaborator Author

@GawainLynch - You have reminded me once again why I submit PRs and have you review them. Do you have any job openings? I would love for you to be my boss. ;) :)

Seriously though, thank you @GawainLynch for the review. I will revise my code as requested, and I hope to push some changes within the next few days.

@GwendolenLynch
Copy link
Contributor

GwendolenLynch commented Apr 1, 2018

No worries mate … Being you, I thought I'd go a bit harder than normal. 😺

Also, @xiaohutai is on leave, so someone has to harass people for no good reason 😇

@xiaohutai
Copy link
Owner

Hi @Raistlfiren ,

I'm wondering why would you want this? This feature disables the website, so that you only get the JSONAPI.

Also when doing:

$this->setDisableFrontend($config['disablefrontend']);

I think you need to add a isset check, so it wouldn't break when updating and that value is not present?

@Raistlfiren
Copy link
Collaborator Author

@xiaohutai - I was wanting to add the feature because we are only using the Bolt instance for the API to feed child websites. We have no need for the frontend. It would be handy to be able to disable the frontend completely, and only include the backend and jsonapi routes.

I tested having no value in my config for disableFrontend, and the value actually returns NULL.

Is the check necessary? I bet @GawainLynch has his own two cents. ;) lol

@xiaohutai
Copy link
Owner

It's an array, it will give a notice if it's not there:

jsonapi-notice

Maybe:

        $disablefrontend = isset($config['disablefrontend']) ? $config['disablefrontend'] : true;
        $this->setDisableFrontend($disablefrontend);

what do you think?

@Raistlfiren
Copy link
Collaborator Author

I agree @xiaohutai, but I did set the default to false instead of true. Since currently the frontend is always displayed.

@xiaohutai xiaohutai merged commit d99e355 into xiaohutai:master Apr 20, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants