From 8d5a4410f77af124cfb894c28239cf24d34d5dde Mon Sep 17 00:00:00 2001 From: Dennis Koch Date: Wed, 31 Mar 2021 07:41:34 +0200 Subject: [PATCH] feat: Config option to set default protocol to https (#110) * feat: Config option to set default protocol to https * style: Fix for StyleCI --- app/Commands/ShareCurrentWorkingDirectoryCommand.php | 11 ++++++++--- config/expose.php | 12 ++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/Commands/ShareCurrentWorkingDirectoryCommand.php b/app/Commands/ShareCurrentWorkingDirectoryCommand.php index 7363c60..5d2aad7 100644 --- a/app/Commands/ShareCurrentWorkingDirectoryCommand.php +++ b/app/Commands/ShareCurrentWorkingDirectoryCommand.php @@ -59,14 +59,19 @@ class ShareCurrentWorkingDirectoryCommand extends ShareCommand return str_replace('.', '-', basename($projectPath)); } - protected function prepareSharedHost($host): string + protected function detectProtocol($host): string { $certificateFile = ($_SERVER['HOME'] ?? $_SERVER['USERPROFILE']).DIRECTORY_SEPARATOR.'.config'.DIRECTORY_SEPARATOR.'valet'.DIRECTORY_SEPARATOR.'Certificates'.DIRECTORY_SEPARATOR.$host.'.crt'; if (file_exists($certificateFile)) { - return 'https://'.$host; + return 'https://'; } - return $host; + return config('expose.default_https', false) ? 'https://' : 'http://'; + } + + protected function prepareSharedHost($host): string + { + return $this->detectProtocol($host).$host; } } diff --git a/config/expose.php b/config/expose.php index f1a754f..8ed7dab 100644 --- a/config/expose.php +++ b/config/expose.php @@ -55,6 +55,18 @@ return [ */ 'default_tld' => 'test', + /* + |-------------------------------------------------------------------------- + | Default HTTPS + |-------------------------------------------------------------------------- + | + | Whether to use HTTPS as a default when sharing your local sites. Expose + | will try to look up the protocol if you are using Laravel Valet + | automatically. Otherwise you can specify it here manually. + | + */ + 'default_https' => false, + /* |-------------------------------------------------------------------------- | Maximum Logged Requests