Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions config/bolt/config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# Note: Database setup is best done in ENV variables. See the file `.env`
# in the project root.
# Note: Database setup is done in ENV variables. See `.env` in the project root.

# The name of the website
sitename: Bolt Core Git Clone
payoff: The amazing payoff goes here

secret: '%env(APP_SECRET)%'

# The theme to use.
#
# Dont edit the provided templates directly, because they _will_ get updated
# in next releases. If you wish to modify a default theme, copy its folder, and
# change the name here accordingly.
theme: skeleton
#theme: bolt-tufte-theme

# Set the timezone to be used on the website. For a list of valid timezone
# settings, see: http://php.net/manual/en/timezones.php
Expand All @@ -23,13 +19,6 @@ theme: skeleton
# format settings, see: https://www.php.net/manual/en/function.date.php
date_format: 'F j, Y H:i'

# Set maintenance mode on or off.
#
# The default for the Maintenance mode (503) page. Can be an (array of) template
# names or identifiers for records, which will be tried until a match is found.
maintenance_mode: false
maintenance: [ blocks/503-maintenance-mode, 'helpers/page_503.html.twig' ]

# The hour of the day for the internal cron task scheduler to run daily, weekly,
# monthly and yearly jobs.
#
Expand Down Expand Up @@ -64,14 +53,29 @@ omit_backgrounds: true
homepage: homepage
homepage_template: index.twig

# The default content for the 404 page. Can be an (array of) template names or
# identifiers for records, which will be tried until a match is found.
# The default content for the "Not Found" (404) page. Can be an (array of) template
# names or identifiers for records, which will be tried until a match is found.
notfound: [ blocks/404-not-found, 'helpers/page_404.html.twig' ]

# The default content for the 403 page. Can be an (array of) template names or
# identifiers for records, which will be tried until a match is found.
# Toggle maintenance mode on or off. Note: If you're logged in, you'll still see
# the website as usual. Use an incognito window to see the "maintenance" page.
maintenance_mode: false

# The default for the "Maintenance mode" (503) page. Can be an (array of) template
# names or identifiers for records, which will be tried until a match is found.
maintenance: [ blocks/503-maintenance-mode, 'helpers/page_503.html.twig' ]

# The default content for the "Forbidden" (403) page. Can be an (array of) template
# names or identifiers for records, which will be tried until a match is found.
forbidden: [ blocks/403-forbidden, 'helpers/page_403.html.twig' ]

# The default content for the "Internal Server Error" (500) page. Can be an
# (array of) template names or identifiers for records.
# Note: Only used in `APP_ENV=prod` mode. You're advised to keep this as simple
# as possible, because if an error occurs in this template, it can not be
# handled, and you'll have a bad time debugging it!
internal_server_error: [ 'helpers/page_500.html.twig' ]

# The default template and amount of records to use for listing-pages on the
# site.
#
Expand Down Expand Up @@ -104,11 +108,6 @@ listing_sort: datepublish DESC
# example in `type: select`.
maximum_listing_select: 1000

# Because of limitations on how the underlying database queries work, there are
# only two options for sorting on taxonomies. ASC for roughly "oldest first"
# and DESC for roughly newest first.
taxonomy_sort: DESC

# Template for showing the search results. If not defined, uses the settings for
# listing_template and listing_records.
#
Expand Down Expand Up @@ -225,3 +224,5 @@ wysiwyg:
# Enforcing the use of SSL. If set, all pages will enforce an SSL connection,
# and redirect to HTTPS if you attempt to visit plain HTTP pages.
# enforce_ssl: true

secret: '%env(APP_SECRET)%'
26 changes: 25 additions & 1 deletion src/Controller/ErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Bolt\Configuration\Config;
use Bolt\Controller\Frontend\DetailControllerInterface;
use Bolt\Controller\Frontend\TemplateController;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ErrorController as SymfonyErrorController;
Expand All @@ -26,14 +27,18 @@ class ErrorController extends SymfonyErrorController
/** @var DetailControllerInterface */
private $detailController;

public function __construct(HttpKernelInterface $httpKernel, Config $config, DetailControllerInterface $detailController, TemplateController $templateController, ErrorRendererInterface $errorRenderer)
/** @var ContainerInterface */
private $container;

public function __construct(HttpKernelInterface $httpKernel, Config $config, DetailControllerInterface $detailController, TemplateController $templateController, ErrorRendererInterface $errorRenderer, ContainerInterface $container)
{
$this->config = $config;
$this->templateController = $templateController;

parent::__construct($httpKernel, $templateController, $errorRenderer);

$this->detailController = $detailController;
$this->container = $container;
}

/**
Expand Down Expand Up @@ -68,6 +73,12 @@ public function showAction(Environment $twig, \Throwable $exception): Response
return $this->showForbidden();
}

$prod = ($this->container->getParameter('kernel.environment') === 'prod');

if ($code === Response::HTTP_INTERNAL_SERVER_ERROR && $prod && $this->config->get('general/internal_server_error')) {
return $this->showInternalServerError();
}

// If not a 404, we'll let Symfony handle it as usual.
return parent::__invoke($exception);
}
Expand Down Expand Up @@ -98,6 +109,19 @@ private function showForbidden(): Response
return new Response('403: Forbidden (and there was no proper page configured to display)');
}

private function showInternalServerError(): Response
{
foreach ($this->config->get('general/internal_server_error') as $item) {
$output = $this->attemptToRender($item);

if ($output instanceof Response) {
return $output;
}
}

return new Response('500: Internal Server Error (and there was no proper page configured to display)');
}

private function showMaintenance(): Response
{
foreach ($this->config->get('general/maintenance') as $item) {
Expand Down
22 changes: 22 additions & 0 deletions templates/helpers/page_403.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ exception.statusCode }} :: {{ exception.message }}</title>
<link rel="stylesheet" href="https://unpkg.com/purecss@1.0.1/build/pure-min.css" integrity="sha384-oAOxQR6DkCoMliIh8yFnu25d7Eq/PHS21PClpwjOTeU2jRSq11vu66rf90/cZr47" crossorigin="anonymous">
</head>

<body id="home">

<div style="padding: 2rem 4rem;">

<h1>{{ exception.statusCode }} :: {{ exception.message }} </h1>

<p>In <code>{{ exception.file|split('/')|slice(-2)|join('/') }}</code></p>

{# will only be shown if debug is on. #}
{{ dump(exception) }}

</div>
</body>
</html>
24 changes: 24 additions & 0 deletions templates/helpers/page_500.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>500 :: Internal Server Error</title>
<link rel="stylesheet" href="https://unpkg.com/purecss@1.0.1/build/pure-min.css" integrity="sha384-oAOxQR6DkCoMliIh8yFnu25d7Eq/PHS21PClpwjOTeU2jRSq11vu66rf90/cZr47" crossorigin="anonymous">
</head>

<body id="home">

<div style="padding: 2rem 4rem;">

<h1>500 :: Internal Server Error</h1>

<h2>The server returned a <code>500</code> status code.</h2>

<p>
Something is broken. Please let us know what you were doing when this error occurred.
We will fix it as soon as possible. Sorry for any inconvenience caused.
</p>

</div>
</body>
</html>