Added new IS_HTTPS_ENABLED env var and deprecated USE_HTTPS

This commit is contained in:
Alejandro Celaya 2021-12-10 16:24:38 +01:00
parent 00f867c6ee
commit 0d936425c2
3 changed files with 15 additions and 9 deletions

View file

@ -31,7 +31,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
* [#1001](https://github.com/shlinkio/shlink/issues/1001) Increased required MSI to 83%. * [#1001](https://github.com/shlinkio/shlink/issues/1001) Increased required MSI to 83%.
### Deprecated ### Deprecated
* *Nothing* * [#1260](https://github.com/shlinkio/shlink/issues/1260) Deprecated `USE_HTTPS` env var that was added in previous release, in favor of the new `IS_HTTPS_ENABLED`.
The old one proved to be confusing and misleading, making people think it was used to actually enable HTTPS transparently, instead of its actual purpose, which is just telling Shlink it is being served with HTTPS.
### Removed ### Removed
* *Nothing* * *Nothing*

View file

@ -8,13 +8,17 @@ use const Shlinkio\Shlink\DEFAULT_SHORT_CODES_LENGTH;
use const Shlinkio\Shlink\MIN_SHORT_CODES_LENGTH; use const Shlinkio\Shlink\MIN_SHORT_CODES_LENGTH;
return (static function (): array { return (static function (): array {
$shortCodesLength = (int) env('DEFAULT_SHORT_CODES_LENGTH', DEFAULT_SHORT_CODES_LENGTH); $shortCodesLength = max(
$shortCodesLength = $shortCodesLength < MIN_SHORT_CODES_LENGTH ? MIN_SHORT_CODES_LENGTH : $shortCodesLength; (int) env('DEFAULT_SHORT_CODES_LENGTH', DEFAULT_SHORT_CODES_LENGTH),
MIN_SHORT_CODES_LENGTH,
);
$resolveSchema = static function (): string { $resolveSchema = static function (): string {
$useHttps = env('USE_HTTPS'); // Deprecated. For v3, set this to true by default, instead of null // Deprecated. For v3, IS_HTTPS_ENABLED should be true by default, instead of null
if ($useHttps !== null) { // return ((bool) env('IS_HTTPS_ENABLED', true)) ? 'https' : 'http';
$boolUseHttps = (bool) $useHttps; $isHttpsEnabled = env('IS_HTTPS_ENABLED', env('USE_HTTPS'));
return $boolUseHttps ? 'https' : 'http'; if ($isHttpsEnabled !== null) {
$boolIsHttpsEnabled = (bool) $isHttpsEnabled;
return $boolIsHttpsEnabled ? 'https' : 'http';
} }
return env('SHORT_DOMAIN_SCHEMA', 'http'); return env('SHORT_DOMAIN_SCHEMA', 'http');

View file

@ -12,7 +12,7 @@ It exposes a shlink instance served with [openswoole](https://www.swoole.co.uk/)
The most basic way to run Shlink's docker image is by providing these mandatory env vars. The most basic way to run Shlink's docker image is by providing these mandatory env vars.
* `DEFAULT_DOMAIN`: The default short domain used for this shlink instance. For example **doma.in**. * `DEFAULT_DOMAIN`: The default short domain used for this shlink instance. For example **doma.in**.
* `USE_HTTPS`: Either **true** or **false**. * `IS_HTTPS_ENABLED`: Either **true** or **false**. Tells if Shlink is being served with HTTPs or not.
* `GEOLITE_LICENSE_KEY`: Your GeoLite2 license key. [Learn more](https://shlink.io/documentation/geolite-license-key/) about this. * `GEOLITE_LICENSE_KEY`: Your GeoLite2 license key. [Learn more](https://shlink.io/documentation/geolite-license-key/) about this.
To run shlink on top of a local docker service, and using an internal SQLite database, do the following: To run shlink on top of a local docker service, and using an internal SQLite database, do the following:
@ -22,7 +22,7 @@ docker run \
--name shlink \ --name shlink \
-p 8080:8080 \ -p 8080:8080 \
-e DEFAULT_DOMAIN=doma.in \ -e DEFAULT_DOMAIN=doma.in \
-e USE_HTTPS=true \ -e IS_HTTPS_ENABLED=true \
-e GEOLITE_LICENSE_KEY=kjh23ljkbndskj345 \ -e GEOLITE_LICENSE_KEY=kjh23ljkbndskj345 \
shlinkio/shlink:stable shlinkio/shlink:stable
``` ```