Polymer / polymer-starter-kit

A starting point for Polymer apps
2.46k stars 660 forks source link

Force HTTPS with Github Pages deployment #644

Closed abdonrd closed 8 years ago

abdonrd commented 8 years ago

Force HTTPS with Github Pages deployment.

robdodson commented 8 years ago

Looking at the gulp-gh-pages task it mentions that it will default to the remote URL you're project is setup with (https://github.com/shinnn/gulp-gh-pages#optionsremoteurl). Does that mean if I clone with https I'd get this behavior by default?

VikramTiwari commented 8 years ago

@abdonrd If you are deploying on GitHub pages, they are always deployed on HTTPs. What GitHub should also do is upgrade HTTP requests to HTTPs. But I guess they have their reasons.

@robdodson My question is that even if the site can serve/is serving on HTTPs, but user is there on HTTP, will the service worker actually perform?

robdodson commented 8 years ago

@VikramTiwari I think (but may be mistaken) that @abdonrd was referring to the gulp task which may attempt to use SSH keys to deploy (but I'll let @abdonrd clarify).

@VikramTiwari no, service workers will only run on https. I don't think GitHub redirects http requests to the https version, but if you're running your own server you can do it. For instance App Engine has an secure: always key which will automatically redirect http requests to https.

abdonrd commented 8 years ago

Sorry for the poor explication! :sweat_smile:

I want to force HTTPS because the Service Worker only runs on HTTPS. I was referring precisely to redirect HTTP to HTTPS.

robdodson commented 8 years ago

Ah yeah, I guess you could do something like this: https://gist.github.com/konklone/9968713

Maybe we could add that to the GH Pages recipe. Would either of you be interested in trying it out and doing a PR if it works?

VikramTiwari commented 8 years ago

@robdodson I am running nginx proxy and redirecting each request to HTTPs using 301 redirect on my servers. But this is an easy fix on the front end. Works! :+1:

abdonrd commented 8 years ago

@robdodson the solutions of your link works. :)

As we will only add the script to the GH Pages recipe, we can add this:

Normal:

<script>
  if (window.location.protocol !== 'https:') {
    window.location.protocol = 'https';
  }
</script>

Compressed:

<script>'https:'!==window.location.protocol&&(window.location.protocol='https')</script>

Or the deploy-gh-pages task could add?

robdodson commented 8 years ago

yeah I think it'd be better to add it to the recipe. Any interest in putting together a PR for it?

abdonrd commented 8 years ago

@robdodson sure, one minute!

abdonrd commented 8 years ago

@robdodson you can check here: https://github.com/PolymerElements/polymer-starter-kit/pull/650. :sunny:

robdodson commented 8 years ago

Fixed in https://github.com/PolymerElements/polymer-starter-kit/pull/650