Skip to content

Commit

Permalink
Stop prefixing redirect target with https:// unless necessary.
Browse files Browse the repository at this point in the history
Also release 1.5.1
  • Loading branch information
SteveLTN committed Jan 29, 2019
1 parent 47a50c3 commit c1a7856
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
17 changes: 13 additions & 4 deletions README.md
Expand Up @@ -144,15 +144,24 @@ Once you are done testing, you can deploy your application stack to the server.

### Redirections

HTTPS-PORTAL support quick setup for redirections. It is deliberately made to
support https targets only because otherwise it'd be against the idea of this project.
HTTPS-PORTAL support quick setup for redirections.

```yaml
https-portal:
# ...
environment:
STAGE: local
DOMAINS: 'example.com => https://target.example.com/foo/bar' # Notice it's "=>" instead of the normal "->"
DOMAINS: 'example.com => https://target.example.com' # Notice it's "=>" instead of the normal "->"
```

All paths will be redirected to the target. E.g. `https://example.com/foo/bar` will be 301 redirected to `https://target.example.com/foo/bar`.

A common use case is to redirect `www.example.com` to `example.com`:

```yaml
https-portal:
# ...
environment:
DOMAINS: 'www.example.com => https://example.com' # Notice it's "=>" instead of the normal "->"
```

### Automatic Container Discovery
Expand Down
2 changes: 1 addition & 1 deletion fs_overlay/etc/cont-init.d/00-welcome
Expand Up @@ -2,6 +2,6 @@

echo '
========================================
HTTPS-PORTAL v1.5.0
HTTPS-PORTAL v1.5.1
========================================
'
10 changes: 9 additions & 1 deletion fs_overlay/opt/certs_manager/models/domain.rb
Expand Up @@ -77,7 +77,15 @@ def upstream
end

def redirect_target_url
parsed_descriptor[:upstream] if parsed_descriptor[:mode] == '=>'
return unless parsed_descriptor[:mode] == '=>'

url = parsed_descriptor[:upstream]

if url.start_with? "http"
return url
else
return "https://" + url
end
end

def stage
Expand Down
2 changes: 1 addition & 1 deletion fs_overlay/var/lib/nginx-conf/default.conf.erb
Expand Up @@ -4,7 +4,7 @@ server {

<% if domain.redirect_target_url %>
location / {
return 301 https://<%= domain.redirect_target_url %>$request_uri;
return 301 <%= domain.redirect_target_url %>$request_uri;
}
<% else %>
location / {
Expand Down
2 changes: 1 addition & 1 deletion fs_overlay/var/lib/nginx-conf/default.ssl.conf.erb
Expand Up @@ -52,7 +52,7 @@ server {
}
<% elsif domain.redirect_target_url %>
location / {
return 301 https://<%= domain.redirect_target_url %>$request_uri;
return 301 <%= domain.redirect_target_url %>$request_uri;
}
<% else %>
location / {
Expand Down
2 changes: 2 additions & 0 deletions spec/models/domain_spec.rb
Expand Up @@ -18,6 +18,8 @@
["example.com \n-> http://target \n", 'example.com', 'http://target', nil, 'local', nil, nil, nil],
["example.com\n-> http://target ", 'example.com', 'http://target', nil, 'local', nil, nil, nil],
['example.com => http://target', 'example.com', nil, 'http://target', 'local', nil, nil, nil],
['example.com => https://target', 'example.com', nil, 'https://target', 'local', nil, nil, nil],
['example.com => target', 'example.com', nil, 'https://target', 'local', nil, nil, nil],
['example.com=>http://target', 'example.com', nil, 'http://target', 'local', nil, nil, nil],
['example.com -> http://target #staging', 'example.com', 'http://target', nil, 'staging', nil, nil, nil],
['example.com => http://target #staging', 'example.com', nil, 'http://target', 'staging', nil, nil, nil],
Expand Down

0 comments on commit c1a7856

Please sign in to comment.