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

feat(frankenphp): make HTTP to HTTPS redirection opt-in #814

Merged
merged 3 commits into from
Jan 16, 2024
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
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