angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

keep get [WDS] disconnected!

Open luzly opened this issue 9 years ago • 44 comments

OS?

Windows 10

Versions.

@angular/cli: 1.0.0-beta.32.3 [1.0.0-beta.24] node: 6.9.1 os: win32 x64 @angular/common: 2.4.8 @angular/compiler: 2.4.8 @angular/core: 2.4.8 @angular/forms: 2.4.8 @angular/http: 2.4.8 @angular/platform-browser: 2.4.8 @angular/platform-browser-dynamic: 2.4.8 @angular/router: 3.4.8 @angular/cli: 1.0.0-beta.32.3 @angular/compiler-cli: 2.4.8

Repro steps.

use ng new PROJECT create a new project without any modification, keep get [WDS] disconnected! error after ng serve.

image

The error only appears under Chrome, both version 55 and 56, it works fine in Mircrosoft Edge and other browsers. I've searched the internet, most solution is about webpack, but I don't know how to config this with angular-cli. I wonder whether this is a bug related to Chrome or not, anyway, even a newly created project suffers.

Thank you for help!

luzly avatar Feb 20 '17 07:02 luzly

@cwalv Those attributes passed as first options to selfsigned.generate() function containing subjectAltName is not the one Chrome is complaining. It is SAN extension field and should be included in the second options object. You can see the options from selfsigned manual. extensions: [{ name: 'basicConstraints', cA: true }], // certificate extensions array

veke avatar Jul 11 '17 22:07 veke

@veke, So did you manage to create one with node.js? Just wonder if it's easier because all the instructions for OpenSSL look a bit complicated.

I made my a cert with the PowerShell command New-SelfSignedCertificate, but it's only available in Windows 10 (and maybe 8).

violinbg avatar Jul 11 '17 23:07 violinbg

@violinbg @cwalv I got green certificate in chrome with this:

const fs = require("fs");
const selfsigned = require("selfsigned");
const attrs = [{ name: "commonName", value: "localhost" }];
const pems = selfsigned.generate(attrs, {
    algorithm: "sha256",
    keySize: 2048,
    extensions: [{
        name: "subjectAltName",
        altNames: [{
            type: 2, // DNS
            value: "localhost"
        }]
    }]
});

fs.writeFileSync("./ssl/server.crt", pems.cert, { encoding: "utf-8" });
fs.writeFileSync("./ssl/server.key", pems.private, { encoding: "utf-8" });

It is valid for 365 days (default value). Made a sslgen.js file to project root folder. Then I also added cert to keychains as trusted. works

veke avatar Jul 12 '17 00:07 veke

@veke Thanks! That script will come handy :)

violinbg avatar Jul 12 '17 01:07 violinbg

Edited extension parameters. Removed URI and IP. Still got green certificate.

veke avatar Jul 12 '17 08:07 veke

i am using nginx but the cert generated by selfsigned(node) not working with my domain https://mydomain.m? some idea?,

fernandops26 avatar Jul 12 '17 21:07 fernandops26

Did you added it in your OS too?

veke avatar Jul 12 '17 21:07 veke

@veke yes :(, Neither with localhost localhost

fernandops26 avatar Jul 12 '17 21:07 fernandops26

if you have latest browsers and cli installed, I have no idea. This is strange that some work for other and other not. Try to add those IP and URI fields back to script.

{
   type: 6, // URI 
   value: 'localhost' // example
},
{
    type: 7, // IP 
    ip: '127.0.0.1'
  }

I got green certificate with that node script in two machines running OSX (haven't tested on windows yet)

veke avatar Jul 12 '17 21:07 veke

What is the error in your certificate? In Chrome you need to open your dev-tools and look for security tab.

veke avatar Jul 12 '17 21:07 veke

@veke this is the error: "There are issues with the site's certificate chain (net::ERR_CERT_AUTHORITY_INVALID)."

fernandops26 avatar Jul 12 '17 21:07 fernandops26

@veke the code for generate cert:

const fs = require("fs");
const selfsigned = require("selfsigned");
const attrs = [{ name: "commonName", value: "mydomain.m" }];
const pems = selfsigned.generate(attrs, {
    algorithm: "sha256",
    keySize: 2048,
    extensions: [{
        name: "subjectAltName",
        altNames: [{
            type: 2, // DNS
            value: "localhost"
        },
	{
   	    type: 6, // URI 
            value: 'https://mydomain.m'
        },
        {
            type: 7, // IP 
            ip: '127.0.0.1'
        }
       	]
    }]
});

fs.writeFileSync("./server.crt", pems.cert, { encoding: "utf-8" });
fs.writeFileSync("./server.key", pems.private, { encoding: "utf-8" });

fernandops26 avatar Jul 12 '17 21:07 fernandops26

I deal this stuff only with local development / angular related stuff. Im not even sure you can use these in real domains :D I've seen commonName values *domain.com sometimes, maybe they need to match to those subjectAltname fields somehow... I have no idea, sorry.

veke avatar Jul 12 '17 21:07 veke

@fernandops26 Certificates are read by the browser. The browser goes to a certification authority to validate the certificate. The certification authority says if the certificate is correct. With a self signed certificate there is no certification authority - so the browser can't trust it.

For a local dev environment, you can see its your certificate and so can choose to trust it - but its still not a correct certificate as it's self signed and doesn't have a certification authority associated with it. So the browser raises this ERR_CERT_AUTHORITY_INVALID.

The trick (which I still don't know how) is to get the browser to trust the certificate for your dev environment. You shouldn't ever trust a self signed certificate from real server and system admins shouldn't have a self signed certificate on a server to make it work.

This is my "basic" understanding of certificates at the moment

pdbroadfoot avatar Jul 24 '17 22:07 pdbroadfoot

I used @veke code and it worked: image

  1. generate your own cert using this code.
  2. install that cert in User Store > Trusted Root Certification (windows 10)
  3. Tell webpack to use that cert by "--https --cert ./ssl/server.crt --key ./ssl/server.key
  4. Profit
  5. Take printscreens and write a readme.txt in ./ssl for next year.

abergs avatar Jul 27 '17 11:07 abergs

[SOLVED] With this reference you can also solve the problem, thanks: https://alexanderzeitler.com/articles/Fixing-Chrome-missing_subjectAltName-selfsigned-cert-openssl/

fernandops26 avatar Jul 27 '17 13:07 fernandops26

[SOLVED] run the angular app using npm start instead of ng serve

aashish-ak avatar May 22 '18 09:05 aashish-ak

thanks @abergs for your solution. That worked for me.

Cubelaster avatar Jul 16 '18 08:07 Cubelaster

I created file vue.config.js in root project with content below:

module.exports = {
  devServer: {
    disableHostCheck: true
  }
}

To me solved!

farnetani avatar Dec 23 '18 22:12 farnetani

@farnetani Are you using Vue? I think you're in a wrong repo. If you could explain and demonstrate that your solution will work in Angular CLI then it would be very much helpful.

whizkidwwe1217 avatar Dec 24 '18 10:12 whizkidwwe1217