Improvements to automatic redirect on loading SEA module (#1055)

* Warn on automatic redirect to HTTPS

* Don't redirect to HTTPS on loopback IP addresses

* Check if current location is a local loopback IP address (127.0.0.0/8) and do not redirect
This commit is contained in:
Yang Hanlin 2021-03-05 06:30:41 +08:00 committed by GitHub
parent 5be57c3fb1
commit ae6d5cb6bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

2
sea.js
View File

@ -35,7 +35,9 @@
try{ if(SEA.window){
if(location.protocol.indexOf('s') < 0
&& location.host.indexOf('localhost') < 0
&& ! /^127\.\d+\.\d+\.\d+$/.test(location.hostname)
&& location.protocol.indexOf('file:') < 0){
console.warn('WebCrypto used by GUN SEA implementation does not work without HTTPS. Will automatically redirect.')
location.protocol = 'https:'; // WebCrypto does NOT work without HTTPS!
}
} }catch(e){}