Skip to content

svelte-kit preview --https ... ignores custom cert in config.kit.vite.[preview|server].https #5312

@alipi

Description

@alipi

Describe the bug

The custom cert config in config.kit.vite.[preview|server].https is now ignored by svelte-kit preview --https ....

This patch works, but I don't know if it's the correct fix:

$ cat @sveltejs+kit+1.0.0-next.355.patch
diff --git a/node_modules/@sveltejs/kit/dist/cli.js b/node_modules/@sveltejs/kit/dist/cli.js
index 8b3547b..b868a2e 100644
--- a/node_modules/@sveltejs/kit/dist/cli.js
+++ b/node_modules/@sveltejs/kit/dist/cli.js
@@ -181,7 +181,7 @@ prog
                        // optional config from command-line flags
                        // these should take precedence, but not print conflict warnings
                        if (host) vite_config.preview.host = host;
-                       if (https) vite_config.preview.https = https;
+                       if (https) vite_config.preview.https = vite_config.preview.https || https;
                        if (port) vite_config.preview.port = port;
 
                        const preview_server = await vite.preview(vite_config);

Reproduction

svelte.config.js:

config.kit.vite.preview = {
   https: {
      key: readFileSync(resolve(__dirname, "my-dev.key"), "utf8"),
      cert: readFileSync(resolve(__dirname, "my-dev.crt"), "utf8")
   }
};

run:
$ npx svelte-kit preview --https --host --port 5000

Some internally created cert is returned instead of the one specified in the config.

$ openssl s_client -showcerts -servername localhost -connect localhost:5000 <<< "Q" | openssl x509 -text | grep -iA2 "Validity"
depth=0 CN = example.org, C = US, ST = Virginia, L = Blacksburg, O = Test, OU = Test
verify error:num=18:self-signed certificate
verify return:1
depth=0 CN = example.org, C = US, ST = Virginia, L = Blacksburg, O = Test, OU = Test
verify return:1
DONE
        Validity
            Not Before: Jun 29 10:05:25 2022 GMT
            Not After : Jul 29 10:05:25 2022 GMT

Logs

No response

System Info

$ npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"

  System:
    OS: Linux 5.10 Generic 36 (Generic) 36 (Generic)
    CPU: (8) x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
    Memory: 14.75 GB / 15.59 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.14.0 - /usr/bin/node
    npm: 8.13.1 - /usr/local/bin/npm

Severity

blocking an upgrade

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions