webpack dev server and https: This site can’t be reached

Viewed 580

I am struggling to configure https in webpack-dev-server and provide self-sign certificate.

There was similar question but it didn't help much as I am using unoffical port and it works fine when I disable https.

The certificate is generated via powershell command New-SelfSignedCertificate and then imported with Import-PfxCertificate

Perhaps certificate is badly formed as when I view site information on Chrome is states the connection to the site is not secure.

Any thoughts?

Thanks for help

package.json

"devDependencies": {
    "webpack": "^5.64.4",
    "webpack-cli": "^4.9.1",
    "webpack-dev-server": "^4.6.0",
}

webpack.config.js

 devServer: {
        hot: true,
        server: {
            type: "https",
            options: {
                pfx: "./localhost.pfx",
                passphrase: "abc123",
                requestCert: true,
            },
        },
        port: 9000,
        historyApiFallback: true,
    }

The tool which is used for generating certifciate.


$dnsName = "localhost"
$expiry = [DateTime]::Now.AddYears(1);
$webDir = "$PSScriptRoot\ClientApp";
$fileName = "localhost.pfx";
$passwordText = "abc123";
$name = "Test App";

Write-Host "Creating cert directly into CurrentUser\My store"

$certificate = New-SelfSignedCertificate `
    -CertStoreLocation Cert:\CurrentUser\My `
    -Subject $name `
    -FriendlyName $name `
    -DnsName $dnsName `
    -NotAfter $expiry

$certFile = Join-Path $webdir $fileName

Write-Host "Exporting certificate to $certFile"

$password = ConvertTo-SecureString `
    -String $passwordText `
    -Force -AsPlainText

Export-PfxCertificate `
    -Cert $certificate `
    -FilePath $certFile `
    -Password $password | Out-Null

Write-Host "Importing $certFile to CurrentUser\Root store for immediate system wide trust"

Import-PfxCertificate `
    -FilePath $certFile `
    -CertStoreLocation Cert:\LocalMachine\Root `
    -Password $password | Out-Null
1 Answers

The requestCert option was causing problems. It worked like a charm when I removed it.

Related