Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

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.

['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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants