Skip to content

Commit

Permalink
[fix] allow passing certificates via config (#2622)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Oct 20, 2021
1 parent d3440cc commit 9bb8aee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-nails-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] allow passing certificates via config
9 changes: 6 additions & 3 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,14 @@ prog
throw Error('Could not find server');
}
// we never start the server on a socket path, so address will be of type AddressInfo
const chosen_port = /** @type {import('net').AddressInfo} */ (
const address_info = /** @type {import('net').AddressInfo} */ (
watcher.vite.httpServer.address()
).port;
);

https = https || !!config.kit.vite().server?.https;
open = open || !!config.kit.vite().server?.open;

welcome({ port: chosen_port, host, https, open });
welcome({ port: address_info.port, host: address_info.address, https, open });
} catch (error) {
handle_error(error);
}
Expand Down
20 changes: 12 additions & 8 deletions packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Watcher extends EventEmitter {
});

/** @type {[any, string[]]} */
let [merged_config, conflicts] = deep_merge(modified_vite_config, {
const [merged_config, conflicts] = deep_merge(modified_vite_config, {
configFile: false,
root: this.cwd,
resolve: {
Expand Down Expand Up @@ -153,13 +153,17 @@ class Watcher extends EventEmitter {

// optional config from command-line flags
// these should take precedence, but not print conflict warnings
[merged_config] = deep_merge(merged_config, {
server: {
host: this.host,
https: this.https,
port: this.port
}
});
if (this.host) {
merged_config.server.host = this.host;
}
// https is already enabled then do nothing. it could be an object and we
// don't want to overwrite with a boolean
if (this.https && !merged_config.server.https) {
merged_config.server.https = this.https;
}
if (this.port) {
merged_config.server.port = this.port;
}

this.vite = await vite.createServer(merged_config);
remove_html_middlewares(this.vite.middlewares);
Expand Down

0 comments on commit 9bb8aee

Please sign in to comment.