@@ -44,7 +44,7 @@ The [Guide](/fetch.html) goes into more detail on configuring specific features.
4444<!-- prettier-ignore-start-->
4545::: warning
4646Like the CLI, the API will automatically load ` .env ` , ` package.json ` and ` wrangler.toml ` files
47- in the current working directory. This may lead to unexpected results . You can
47+ in the current working directory. This may lead to unexpected behaviour . You can
4848disable this by setting ` envPath ` , ` packagePath ` and ` wranglerConfigPath ` options to paths of
4949empty files:
5050
@@ -75,9 +75,9 @@ const mf = new Miniflare({
7575
7676### Watching, Reloading and Disposing
7777
78- You can watch scripts, ` .env ` files and ` wrangler.toml ` files with the ` watch `
79- option. When this is enabled, you must ` dispose ` of the watcher when you're done
80- with the ` Miniflare ` instance:
78+ You can watch scripts, ` .env ` , ` package.json ` and ` wrangler.toml ` files with the
79+ ` watch ` option. When this is enabled, you must ` dispose ` of the watcher when
80+ you're done with the ` Miniflare ` instance:
8181
8282``` js
8383const mf = new Miniflare ({
@@ -90,8 +90,8 @@ await mf.dispose();
9090You must also ` dispose ` if you're persisting KV, cache, or Durable Object data
9191in Redis to close opened connections.
9292
93- You can also manually reload scripts (main and Durable Object's ) and options
94- (` .env ` and ` wrangler.toml ` ) too with ` reloadOptions ` :
93+ You can also manually reload scripts (main and Durable Objects' ) and options
94+ (` .env ` , ` package.json ` and ` wrangler.toml ` ) too with ` reloadOptions ` :
9595
9696``` js
9797const mf = new Miniflare ({ ... });
@@ -101,8 +101,8 @@ await mf.reloadOptions();
101101### Getting Processed Options
102102
103103You can get an object containing processed options with ` getOptions ` . These
104- contain options resolved from the constructor, ` .env ` files and ` wrangler.toml `
105- files.
104+ contain options resolved from the constructor, ` .env ` , ` package.json ` and
105+ ` wrangler.toml ` files:
106106
107107``` js
108108const mf = new Miniflare ({ ... });
@@ -173,6 +173,69 @@ const port = options.port ?? 5000; // Use port 5000 by default
173173mf .createServer ().listen (port, () => { ... });
174174` ` `
175175
176+ ### HTTPS Server
177+
178+ To start an HTTPS server instead, set the ` https` option as described below and
179+ pass ` true ` as the secure argument of ` createServer` . Note that you must now
180+ ` await ` the call to ` createServer` :
181+
182+ ` ` ` js
183+ import { Miniflare } from " miniflare" ;
184+
185+ const mf = new Miniflare ({
186+ ... ,
187+ https: ...
188+ });
189+ (await mf .createServer (true )).listen (5000 , () => {
190+ console .log (" Listening on :5000" );
191+ });
192+ ` ` `
193+
194+ To use an automatically generated self-signed certificate, set ` https` to
195+ ` true ` . This certificate will be valid for 30 days and be cached in ` ./ .mf / cert`
196+ by default. You can customise this directory by setting ` https` to a string path
197+ instead. The certificate will be renewed if it expires in less than 2 days:
198+
199+ ` ` ` js
200+ const mf = new Miniflare ({
201+ https: true , // Cache certificate in ./.mf/cert
202+ https: " ./cert_cache" , // Cache in ./cert_cache instead
203+ });
204+ ` ` `
205+
206+ To load an existing certificate from the file system:
207+
208+ ` ` ` js
209+ const mf = new Miniflare ({
210+ https: {
211+ // These are all optional, you don't need to include them all
212+ keyPath: " ./key.pem" ,
213+ certPath: " ./cert.pem" ,
214+ caPath: " ./ca.pem" ,
215+ pfxPath: " ./pfx.pfx" ,
216+ passphrase: " pfx passphrase" ,
217+ },
218+ });
219+ ` ` `
220+
221+ To load an existing certificate from strings instead:
222+
223+ ` ` ` js
224+ const mf = new Miniflare ({
225+ https: {
226+ // These are all optional, you don't need to include them all
227+ key: " -----BEGIN RSA PRIVATE KEY-----..." ,
228+ cert: " -----BEGIN CERTIFICATE-----..." ,
229+ ca: " ..." ,
230+ pfx: " ..." ,
231+ passphrase: " pfx passphrase" ,
232+ },
233+ });
234+ ` ` `
235+
236+ If both a string and path are specified for an option (e.g. ` key` and
237+ ` keyPath` ), the string will be preferred.
238+
176239### Logging
177240
178241By default, ` [mf: * ]` logs as seen in the CLI are disabled when using the API. To
0 commit comments