-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support https * tidy up, typecheck * clarify * changeset Co-authored-by: Rich Harris <[email protected]>
- Loading branch information
1 parent
ba4f9b7
commit 24fab19
Showing
8 changed files
with
197 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
Add --https flag to dev and start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// @ts-ignore | ||
import { generate } from 'selfsigned'; | ||
|
||
/** | ||
* https://github.com/webpack/webpack-dev-server/blob/master/lib/utils/createCertificate.js | ||
* | ||
* Copyright JS Foundation and other contributors | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file at | ||
* https://github.com/webpack/webpack-dev-server/blob/master/LICENSE | ||
*/ | ||
export function createCertificate() { | ||
const pems = generate(null, { | ||
algorithm: 'sha256', | ||
days: 30, | ||
keySize: 2048, | ||
extensions: [ | ||
{ | ||
name: 'keyUsage', | ||
keyCertSign: true, | ||
digitalSignature: true, | ||
nonRepudiation: true, | ||
keyEncipherment: true, | ||
dataEncipherment: true | ||
}, | ||
{ | ||
name: 'extKeyUsage', | ||
serverAuth: true, | ||
clientAuth: true, | ||
codeSigning: true, | ||
timeStamping: true | ||
}, | ||
{ | ||
name: 'subjectAltName', | ||
altNames: [ | ||
{ | ||
// type 2 is DNS | ||
type: 2, | ||
value: 'localhost' | ||
}, | ||
{ | ||
type: 2, | ||
value: 'localhost.localdomain' | ||
}, | ||
{ | ||
type: 2, | ||
value: 'lvh.me' | ||
}, | ||
{ | ||
type: 2, | ||
value: '*.lvh.me' | ||
}, | ||
{ | ||
type: 2, | ||
value: '[::1]' | ||
}, | ||
{ | ||
// type 7 is IP | ||
type: 7, | ||
ip: '127.0.0.1' | ||
}, | ||
{ | ||
type: 7, | ||
ip: 'fe80::1' | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
|
||
return pems.private + pems.cert; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import http from 'http'; | ||
import https from 'https'; | ||
|
||
/** | ||
* | ||
* @param {number} port | ||
* @param {string} host | ||
* @param {boolean | https.ServerOptions} https_options | ||
* @param {(req: http.IncomingMessage, res: http.ServerResponse) => void} handler | ||
* @returns {Promise<http.Server | https.Server>} | ||
*/ | ||
export async function get_server(port, host, https_options, handler) { | ||
if (https_options) { | ||
https_options = | ||
typeof https_options === 'boolean' ? /** @type {https.ServerOptions} */ ({}) : https_options; | ||
|
||
if (!https_options.key || !https_options.cert) { | ||
https_options.key = https_options.cert = (await import('./cert')).createCertificate(); | ||
} | ||
} | ||
|
||
return new Promise((fulfil) => { | ||
const server = https_options | ||
? https.createServer(/** @type {https.ServerOptions} */ (https_options), handler) | ||
: http.createServer(handler); | ||
|
||
server.listen(port, host || '0.0.0.0', () => { | ||
fulfil(server); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.