Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 96de92a

Browse files
authored
Merge pull request #16 from mrbbot/docs/1.3.0
Version 1.3.0 Docs
2 parents 1eff643 + 236154e commit 96de92a

File tree

12 files changed

+199
-34
lines changed

12 files changed

+199
-34
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
# 🚧 Changelog
22

3+
## 1.3.0
4+
5+
### Features
6+
7+
- Switched to a [`lol-html`](https://github.com/cloudflare/lol-html)-based
8+
WebAssembly implementation of `HTMLRewriter` for a more accurate simulation of
9+
the real Workers environment. See
10+
[📄 HTMLRewriter](https://miniflare.dev/html-rewriter.html) for more details.
11+
- Added HTTPS support for local development, thanks
12+
[@RichiCoder1](https://github.com/RichiCoder1) for the
13+
[suggestion (#12)](https://github.com/mrbbot/miniflare/issues/12). See
14+
[💻 Using the CLI](https://miniflare.dev/cli.html#https-server) and
15+
[🧰 Using the API](https://miniflare.dev/api.html#https-server) for more
16+
details.
17+
- When using the CLI, the `--watch` flag is now assumed if `--build-watch-path`
18+
is set, thanks [@evanderkoogh](https://github.com/evanderkoogh) for the
19+
[PR (#8)](https://github.com/mrbbot/miniflare/pull/8)
20+
- Added source maps to `CommonJS` module transformation
21+
22+
### Fixes
23+
24+
- Switched to real values for the `cf` property, thanks
25+
[@chase](https://github.com/chase) for the
26+
[PR (#11)](https://github.com/mrbbot/miniflare/pull/11)
27+
- Upgraded the TOML parser to support dotted keys, thanks
28+
[@leader22](https://github.com/leader22) for the
29+
[PR (#13)](https://github.com/mrbbot/miniflare/pull/13)
30+
- Added `CryptoKey` to the sandbox, thanks [@mosch](https://github.com/mosch)
31+
for the [PR (#14)](https://github.com/mrbbot/miniflare/pull/14)
32+
333
## 1.2.0
434

535
### Features

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
It's an alternative to `wrangler dev`, written in TypeScript, that runs your
1414
workers in a sandbox implementing Workers' runtime APIs.
1515

16+
Note that Miniflare is not an official Cloudflare product.
17+
1618
**See <https://miniflare.dev> for more detailed documentation.**
1719

1820
## Features
1921

20-
- 📨 Fetch Events (with HTTP server and manual triggering)
21-
- ⏰ Scheduled Events (with manual and cron triggering)
22+
- 📨 Fetch Events (with HTTP(S) server and manual dispatch)
23+
- ⏰ Scheduled Events (with cron triggering and manual dispatch)
2224
- 🔑 Variables and Secrets with `.env` Files
2325
- 📚 Modules Support
2426
- 📦 KV (with optional persistence)
@@ -106,6 +108,12 @@ Options:
106108
-e, --env Path to .env file [string]
107109
-b, --binding Bind variable/secret (KEY=VALUE) [array]
108110
--wasm WASM module to bind (NAME=PATH) [array]
111+
--https Enable self-signed HTTPS
112+
--https-key Path to PEM SSL key [string]
113+
--https-cert Path to PEM SSL cert chain [string]
114+
--https-ca Path to SSL trusted CA certs [string]
115+
--https-pfx Path to PFX/PKCS12 SSL key/cert chain [string]
116+
--https-passphrase Passphrase to decrypt SSL files [string]
109117
--disable-updater Disable update checker [boolean]
110118
```
111119

docs/api.md

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The [Guide](/fetch.html) goes into more detail on configuring specific features.
4444
<!--prettier-ignore-start-->
4545
::: warning
4646
Like 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
4848
disable this by setting `envPath`, `packagePath` and `wranglerConfigPath` options to paths of
4949
empty 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
8383
const mf = new Miniflare({
@@ -90,8 +90,8 @@ await mf.dispose();
9090
You must also `dispose` if you're persisting KV, cache, or Durable Object data
9191
in 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
9797
const mf = new Miniflare({ ... });
@@ -101,8 +101,8 @@ await mf.reloadOptions();
101101
### Getting Processed Options
102102

103103
You 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
108108
const mf = new Miniflare({ ... });
@@ -173,6 +173,69 @@ const port = options.port ?? 5000; // Use port 5000 by default
173173
mf.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
178241
By default, `[mf:*]` logs as seen in the CLI are disabled when using the API. To

docs/builds.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ dir = "" # Defaults to "dist"
4242
main = "./output.js"
4343
```
4444

45+
<!--prettier-ignore-start-->
46+
::: tip
47+
When using the CLI, if `--build-watch-path` is set, `--watch` is automatically
48+
assumed.
49+
:::
50+
<!--prettier-ignore-end-->
51+
4552
## Wrangler Builds
4653

4754
Miniflare supports building `webpack` and `rust` type Wrangler projects too.

docs/cache.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ but not CLI invocations or different `Miniflare` instances. To enable
3030
persistence to the file system or Redis, specify the cache persistence option:
3131

3232
```shell
33-
$ miniflare --cache-persist # Defaults to ./mf/cache
33+
$ miniflare --cache-persist # Defaults to ./.mf/cache
3434
$ miniflare --cache-persist ./data/ # Custom path
3535
$ miniflare --cache-persist redis://localhost:6379 # Redis server
3636
```
3737

3838
```toml
3939
# wrangler.toml
4040
[miniflare]
41-
cache_persist = true # Defaults to ./mf/cache
41+
cache_persist = true # Defaults to ./.mf/cache
4242
cache_persist = "./data/" # Custom path
4343
cache_persist = "redis://localhost:6379" # Redis server
4444
```
4545

4646
```js
4747
const mf = new Miniflare({
48-
cachePersist: true, // Defaults to ./mf/cache
48+
cachePersist: true, // Defaults to ./.mf/cache
4949
cachePersist: "./data", // Custom path
5050
cachePersist: "redis://localhost:6379", // Redis server
5151
});

docs/cli.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ $ miniflare worker.js
4040

4141
<!--prettier-ignore-start-->
4242
::: tip
43-
If you're building your worker beforehand, make sure you pass the path of your built output to Miniflare, not your input source code.
44-
See [🛠 Builds](/builds.html) for more details.
43+
If you're building your worker beforehand (with esbuild, Webpack, etc), make
44+
sure you pass the path of your built output to Miniflare, not your input source
45+
code. See [🛠 Builds](/builds.html) for more details.
46+
47+
If your script is defined in a `wrangler.toml` or `package.json` file, or you're
48+
using Wrangler's `"webpack"` or `"rust"` worker `type`s, you don't need to pass
49+
a script as a command line argument: Miniflare will infer it automatically.
4550
:::
4651
<!--prettier-ignore-end-->
4752

@@ -113,6 +118,27 @@ main = "./worker.js"
113118
}
114119
```
115120

121+
### HTTPS Server
122+
123+
By default, Miniflare starts an HTTP server. To start an HTTPS server instead,
124+
set the `https` option. To use an automatically generated self-signed
125+
certificate, use the `--https` flag. This certificate is cached and will be
126+
valid for 30 days. The certificate will be renewed if it expires in less than 2
127+
days:
128+
129+
```shell
130+
$ miniflare worker.js --https # Cache certificate in ./.mf/cert
131+
$ miniflare worker.js --https ./cert_cache # Cache in ./cert_cache instead
132+
```
133+
134+
To use an existing certificate instead, use the `--https-key`, `--https-cert`,
135+
`--https-ca` and `--https-pfx` to set the paths to it. If these are encrypted,
136+
use the `--https-passphrase` flag to set the passphrase:
137+
138+
```shell
139+
$ miniflare worker.js --https-key ./key.pem --https-cert ./cert.pem
140+
```
141+
116142
### Update Checker
117143

118144
The CLI includes an automatic update checker that looks for new versions of
@@ -157,6 +183,12 @@ Options:
157183
-e, --env Path to .env file [string]
158184
-b, --binding Bind variable/secret (KEY=VALUE) [array]
159185
--wasm WASM module to bind (NAME=PATH) [array]
186+
--https Enable self-signed HTTPS
187+
--https-key Path to PEM SSL key [string]
188+
--https-cert Path to PEM SSL cert chain [string]
189+
--https-ca Path to SSL trusted CA certs [string]
190+
--https-pfx Path to PFX/PKCS12 SSL key/cert chain [string]
191+
--https-passphrase Passphrase to decrypt SSL files [string]
160192
--disable-updater Disable update checker [boolean]
161193
```
162194

@@ -210,4 +242,12 @@ port = 1337 ## --port
210242
wasm_bindings = [ ## --wasm
211243
{ name = "MODULE", path="module.wasm" }
212244
]
245+
https = true ## --https
246+
https = "./cert_cache" ## --https ./cert_cache
247+
[miniflare.https]
248+
key = "./key.pem" ## --https-key
249+
cert = "./cert.pem" ## --https-cert
250+
ca = "./ca.pem" ## --https-ca
251+
pfx = "./pfx.pfx" ## --https-pfx
252+
passphrase = "pfx passphrase" ## --https-passphrase
213253
```

docs/durable-objects.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,22 @@ persistence to the file system or Redis, specify the Durable Object persistence
6262
option:
6363

6464
```shell
65-
$ miniflare --do-persist # Defaults to ./mf/do
65+
$ miniflare --do-persist # Defaults to ./.mf/do
6666
$ miniflare --do-persist ./data/ # Custom path
6767
$ miniflare --do-persist redis://localhost:6379 # Redis server
6868
```
6969

7070
```toml
7171
# wrangler.toml
7272
[miniflare]
73-
durable_objects_persist = true # Defaults to ./mf/do
73+
durable_objects_persist = true # Defaults to ./.mf/do
7474
durable_objects_persist = "./data/" # Custom path
7575
durable_objects_persist = "redis://localhost:6379" # Redis server
7676
```
7777

7878
```js
7979
const mf = new Miniflare({
80-
durableObjectsPersist: true, // Defaults to ./mf/do
80+
durableObjectsPersist: true, // Defaults to ./.mf/do
8181
durableObjectsPersist: "./data", // Custom path
8282
durableObjectsPersist: "redis://localhost:6379", // Redis server
8383
});

docs/html-rewriter.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22

33
- [`HTMLRewriter` Reference](https://developers.cloudflare.com/workers/runtime-apis/html-rewriter)
44

5-
Miniflare includes `HTMLRewriter` in its sandbox. It is powered by
6-
[@worker-tools/parsed-html-rewriter](https://github.com/worker-tools/parsed-html-rewriter).
7-
Note this isn't a streaming parser: the entire document is parsed, then
8-
rewritten. This makes it slower and more memory inefficient than the actual
9-
implementation. This also means the order handlers are called may be different
10-
to real workers.
11-
12-
Ideally, we would use a WebAssembly version of
13-
[lol-html](https://github.com/cloudflare/lol-html), the actual streaming parser
14-
Cloudflare Workers use, but this
15-
[isn't available yet](https://github.com/cloudflare/lol-html/issues/38).
5+
Miniflare includes `HTMLRewriter` in its sandbox. It's powered by
6+
[`html-rewriter-wasm`](https://github.com/mrbbot/html-rewriter-wasm), which uses
7+
a WebAssembly version of [`lol-html`](https://github.com/cloudflare/lol-html),
8+
the same library Cloudflare Workers use for their `HTMLRewriter`.

docs/kv.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ not CLI invocations or different `Miniflare` instances. To enable persistence to
5353
the file system or Redis, specify the KV persistence option:
5454

5555
```shell
56-
$ miniflare --kv-persist # Defaults to ./mf/kv
56+
$ miniflare --kv-persist # Defaults to ./.mf/kv
5757
$ miniflare --kv-persist ./data/ # Custom path
5858
$ miniflare --kv-persist redis://localhost:6379 # Redis server
5959
```
6060

6161
```toml
6262
# wrangler.toml
6363
[miniflare]
64-
kv_persist = true # Defaults to ./mf/kv
64+
kv_persist = true # Defaults to ./.mf/kv
6565
kv_persist = "./data/" # Custom path
6666
kv_persist = "redis://localhost:6379" # Redis server
6767
```
6868

6969
```js
7070
const mf = new Miniflare({
71-
kvPersist: true, // Defaults to ./mf/kv
71+
kvPersist: true, // Defaults to ./.mf/kv
7272
kvPersist: "./data", // Custom path
7373
kvPersist: "redis://localhost:6379", // Redis server
7474
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "miniflare",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Fun, full-featured, fully-local simulator for Cloudflare Workers",
55
"keywords": [
66
"cloudflare",

0 commit comments

Comments
 (0)