Skip to content

Commit

Permalink
feat(frankenphp): make HTTP to HTTPS redirection opt-in (#814)
Browse files Browse the repository at this point in the history
* feat(frankenphp): make HTTP to HTTPS redirection opt-in

* Fix code styling

* formatting

---------

Co-authored-by: dunglas <dunglas@users.noreply.github.com>
Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
3 people authored Jan 16, 2024
1 parent e855b0d commit 2e73236
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Commands/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class StartCommand extends Command implements SignalableCommandInterface
{--rr-config= : The path to the RoadRunner .rr.yaml file}
{--caddyfile= : The path to the FrankenPHP Caddyfile file}
{--https : Enable HTTPS, HTTP/2, and HTTP/3, and automatically generate and renew certificates [FrankenPHP only]}
{--http-redirect : Enable HTTP to HTTPS redirection (only enabled if --https is passed) [FrankenPHP only]}
{--watch : Automatically reload the server when the application is modified}
{--poll : Use file system polling while watching in order to watch files over a network}
{--log-level= : Log messages at or above the specified log level}';
Expand Down Expand Up @@ -108,6 +109,7 @@ protected function startFrankenPhpServer()
'--max-requests' => $this->option('max-requests'),
'--caddyfile' => $this->option('caddyfile'),
'--https' => $this->option('https'),
'--http-redirect' => $this->option('http-redirect'),
'--watch' => $this->option('watch'),
'--poll' => $this->option('poll'),
'--log-level' => $this->option('log-level'),
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/StartFrankenPhpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class StartFrankenPhpCommand extends Command implements SignalableCommandInterfa
{--max-requests=500 : The number of requests to process before reloading the server}
{--caddyfile= : The path to the FrankenPHP Caddyfile file}
{--https : Enable HTTPS, HTTP/2, and HTTP/3, and automatically generate and renew certificates}
{--http-redirect : Enable HTTP to HTTPS redirection (only enabled if --https is passed)}
{--watch : Automatically reload the server when the application is modified}
{--poll : Use file system polling while watching in order to watch files over a network}
{--log-level= : Log messages at or above the specified log level}';
Expand Down Expand Up @@ -75,7 +76,9 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
$host = $this->option('host');
$port = $this->getPort();

$serverName = $this->option('https')
$https = $this->option('https');

$serverName = $https
? "https://$host:$port"
: "http://:$port";

Expand All @@ -90,6 +93,7 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
'LARAVEL_OCTANE' => 1,
'MAX_REQUESTS' => $this->option('max-requests'),
'REQUEST_MAX_EXECUTION_TIME' => $this->maxExecutionTime(),
'CADDY_GLOBAL_OPTIONS' => ($https && $this->option('http-redirect')) ? '' : 'auto_https disable_redirects',
'CADDY_SERVER_ADMIN_PORT' => $this->adminPort(),
'CADDY_SERVER_LOG_LEVEL' => $this->option('log-level') ?: (app()->environment('local') ? 'INFO' : 'WARN'),
'CADDY_SERVER_LOGGER' => 'json',
Expand Down

0 comments on commit 2e73236

Please sign in to comment.