website: Redirecting to https for non-local http urls.

Closes https://github.com/vanadium/issues/issues/1255

Change-Id: Id42a3c892d73afc8fa98fbc0c268a3dd84bea327
diff --git a/browser/index.js b/browser/index.js
index 7a8f21b..6d3dc39 100644
--- a/browser/index.js
+++ b/browser/index.js
@@ -13,6 +13,9 @@
 var Sidebar = React.createFactory(require('./sidebar'));
 var Toc = React.createFactory(require('./toc'));
 
+// Redirect to https url if on http and not localhost.
+ensureHttps();
+
 domready(function() {
   var sidebarEl = dom.find('.sidebar');
   ReactDOM.render(Sidebar({
@@ -114,3 +117,14 @@
     headings: headings
   };
 }
+
+function ensureHttps() {
+  var host = window.location.host;
+  var protocol = window.location.protocol;
+
+  if (protocol !== 'https:' &&
+      !host.startsWith('localhost') &&
+      !host.startsWith('127.0.0.1')) {
+    window.location.href = 'https:' + window.location.href.substring(protocol.length);
+  }
+}