Skip to content

Commit 2e73236

Browse files
feat(frankenphp): make HTTP to HTTPS redirection opt-in (#814)
* feat(frankenphp): make HTTP to HTTPS redirection opt-in * Fix code styling * formatting --------- Co-authored-by: dunglas <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent e855b0d commit 2e73236

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Commands/StartCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class StartCommand extends Command implements SignalableCommandInterface
2626
{--rr-config= : The path to the RoadRunner .rr.yaml file}
2727
{--caddyfile= : The path to the FrankenPHP Caddyfile file}
2828
{--https : Enable HTTPS, HTTP/2, and HTTP/3, and automatically generate and renew certificates [FrankenPHP only]}
29+
{--http-redirect : Enable HTTP to HTTPS redirection (only enabled if --https is passed) [FrankenPHP only]}
2930
{--watch : Automatically reload the server when the application is modified}
3031
{--poll : Use file system polling while watching in order to watch files over a network}
3132
{--log-level= : Log messages at or above the specified log level}';
@@ -108,6 +109,7 @@ protected function startFrankenPhpServer()
108109
'--max-requests' => $this->option('max-requests'),
109110
'--caddyfile' => $this->option('caddyfile'),
110111
'--https' => $this->option('https'),
112+
'--http-redirect' => $this->option('http-redirect'),
111113
'--watch' => $this->option('watch'),
112114
'--poll' => $this->option('poll'),
113115
'--log-level' => $this->option('log-level'),

src/Commands/StartFrankenPhpCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class StartFrankenPhpCommand extends Command implements SignalableCommandInterfa
3030
{--max-requests=500 : The number of requests to process before reloading the server}
3131
{--caddyfile= : The path to the FrankenPHP Caddyfile file}
3232
{--https : Enable HTTPS, HTTP/2, and HTTP/3, and automatically generate and renew certificates}
33+
{--http-redirect : Enable HTTP to HTTPS redirection (only enabled if --https is passed)}
3334
{--watch : Automatically reload the server when the application is modified}
3435
{--poll : Use file system polling while watching in order to watch files over a network}
3536
{--log-level= : Log messages at or above the specified log level}';
@@ -75,7 +76,9 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
7576
$host = $this->option('host');
7677
$port = $this->getPort();
7778

78-
$serverName = $this->option('https')
79+
$https = $this->option('https');
80+
81+
$serverName = $https
7982
? "https://$host:$port"
8083
: "http://:$port";
8184

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

0 commit comments

Comments
 (0)