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

dev-server: pick up scheme and host from forwarding proxy. #2492

Merged
merged 1 commit into from
Jul 22, 2020

Conversation

LeviticusMB
Copy link
Contributor

Read and use X-Forwarded-Host and X-Forwarded-Proto when constructing the dev-server client URL.

This makes it possible to put the dev-server behind and HTTP/2 or TLS proxy, which can redirect requests not only to the dev-server but also all kinds of backend API-services.

For instance, the following nginx config can be used to serve both the dev-server and a couple of API endpoints over HTTP/2.

http {
    ssl_certificate     fullchain.pem;
    ssl_certificate_key privkey.pem;
    ssl_dhparam         ffdhe2048.txt;
    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;

    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }

    proxy_http_version  1.1;
    proxy_set_header    Upgrade             $http_upgrade;
    proxy_set_header    Connection          $connection_upgrade;
    proxy_set_header    Host                $http_host;
    proxy_set_header	X-Forwarded-For	    $remote_addr;
    proxy_set_header	X-Forwarded-Host    $http_host;
    proxy_set_header	X-Forwarded-Proto   $scheme;

    server {
        listen          443 ssl http2;
        listen          [::]:443 ssl http2;

        location / {
            proxy_pass  http://localhost:3333;
        }

        location ~ /(my|api|endpoints).* {
            proxy_pass  http://localhost:3301;
        }
    }
}

@manucorporat
Copy link
Contributor

I would love to merge this PR, but what's the use case? i don't think anyone should use the stencil's dev server in production

@LeviticusMB
Copy link
Contributor Author

My main motivation was simply that I needed to expose a couple of API endpoints that my app requires and this was the easiest way to do that. (But see #896 and #1252)

The fact that I can make my developer environment use exactly the same parameters as the production environment (caching, compression, http/2 instead of https, tls config, redirects and URL aliases etc.) is just a very welcome bonus.

@adamdbradley adamdbradley merged commit 3be1d72 into ionic-team:master Jul 22, 2020
@adamdbradley
Copy link
Contributor

Thanks for the PR, merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants