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

Commit c1a0946

Browse files
committed
Bump versions to 2.0.0-rc.3, update CHANGELOG.md and docs
1 parent 2865304 commit c1a0946

File tree

30 files changed

+548
-302
lines changed

30 files changed

+548
-302
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ goals:
1717
errors of the real Workers runtime, so you'll know before you deploy if
1818
things are going to break.
1919

20+
Check out the [migration guide](https://v2.miniflare.dev/migrating.html) if
21+
you're upgrading from version 1.
22+
2023
### Notable Changes
2124

2225
- ✳️ Node.js 16.7.0 is now the minimum required version
@@ -277,6 +280,8 @@ goals:
277280
header that includes `gzip`, `deflate` or `br` will be automatically encoded.
278281
Closes [issue #72](https://github.com/cloudflare/miniflare/issues/72), thanks
279282
[@SupremeTechnopriest](https://github.com/SupremeTechnopriest).
283+
- `Request`/`Response` `body`s are now byte streams, allowing them to be read
284+
with bring-your-own-buffer readers
280285
- Throw an error when attempting to construct a WebSocket response with a status
281286
other than `101`
282287
- Throw an error when attempting to clone a WebSocket response
@@ -386,7 +391,7 @@ goals:
386391
```
387392

388393
- Split out the Node request to `Request` object conversion logic into a
389-
`convertNodeRequest(req, upstream?, meta?)` function. You can import this from
394+
`convertNodeRequest(req, meta?)` function. You can import this from
390395
`@miniflare/http-server`.
391396
- Only return a pretty-error page when the request `Accept` header includes
392397
`text/html`

docs/api.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,154 @@ const mf = new Miniflare({
335335
const res = await mf.dispatchFetch("http://localhost:8787/");
336336
console.log(await res.text()); // Hello Miniflare!
337337
```
338+
339+
## Reference
340+
341+
```js
342+
import { Miniflare, Log, LogLevel } from "miniflare";
343+
344+
const mf = new Miniflare({
345+
// All options are optional, but one of script or scriptPath is required
346+
347+
log: new Log(LogLevel.INFO), // Logger Miniflare uses for debugging
348+
sourceMap: true, // Enable source map support globally
349+
350+
script: `export default {
351+
async fetch(request, env, ctx) {
352+
return new Response("Hello Miniflare!");
353+
}
354+
}`,
355+
scriptPath: "./index.mjs",
356+
357+
wranglerConfigPath: true, // Load configuration from wrangler.toml
358+
wranglerConfigPath: "./wrangler.custom.toml", // ...or custom wrangler.toml path
359+
360+
wranglerConfigEnv: "dev", // Environment in wrangler.toml to use
361+
362+
packagePath: true, // Load script from package.json
363+
packagePath: "./package.custom.json", // ...or custom package.json path
364+
365+
modules: true, // Enable modules
366+
modulesRules: [
367+
// Modules import rule
368+
{ type: "ESModule", include: ["**/*.js"], fallthrough: true },
369+
{ type: "Text", include: ["**/*.text"] },
370+
],
371+
compatibilityDate: "2021-11-23", // Opt into backwards-incompatible changes from
372+
compatibilityFlags: ["formdata_parser_supports_files"], // Control specific backwards-incompatible changes
373+
upstream: "https://miniflare.dev", // URL of upstream origin
374+
watch: true, // Watch files for changes
375+
mounts: {
376+
// Mount additional named workers
377+
api: "./api",
378+
site: {
379+
rootPath: "./site", // Path to resolve files relative to
380+
scriptPath: "./index.js", // Resolved as ./site/index.js
381+
sitePath: "./public", // Resolved as ./site/public
382+
routes: ["site.mf/*"], // Route requests matching site.mf/* to this worker
383+
},
384+
},
385+
386+
host: "127.0.0.1", // Host for HTTP(S) server to listen on
387+
port: 8787, // Port for HTTP(S) server to listen on
388+
https: true, // Enable self-signed HTTPS (with optional cert path)
389+
httpsKey: "-----BEGIN RSA PRIVATE KEY-----...",
390+
httpsKeyPath: "./key.pem", // Path to PEM SSL key
391+
httpsCert: "-----BEGIN CERTIFICATE-----...",
392+
httpsCertPath: "./cert.pem", // Path to PEM SSL cert chain
393+
httpsCa: "...",
394+
httpsCaPath: "./ca.pem", // Path to SSL trusted CA certs
395+
httpsPfx: "...",
396+
httpsPfxPath: "./pfx.pfx", // Path to PFX/PKCS12 SSL key/cert chain
397+
httpsPassphrase: "pfx passphrase", // Passphrase to decrypt SSL files
398+
cfFetch: "./node_modules/.mf/cf.json", // Path for cached Request cf object from Cloudflare
399+
async metaProvider(req) {
400+
// Custom request metadata provider taking Node `http.IncomingMessage`
401+
return {
402+
forwardedProto: req.headers["X-Forwarded-Proto"],
403+
realIp: req.headers["X-Forwarded-For"],
404+
cf: {
405+
colo: "SFO",
406+
country: "US",
407+
// ...
408+
},
409+
};
410+
},
411+
liveReload: true, // Reload HTML pages whenever worker is reloaded
412+
413+
crons: ["30 * * * *"], // CRON expression for triggering scheduled events
414+
415+
buildCommand: "npm run build", // Command to build project
416+
buildBasePath: "./build", // Working directory for build command
417+
buildWatchPaths: ["./src"], // Directory to watch for rebuilding on changes
418+
419+
kvNamespaces: ["TEST_NAMESPACE"], // KV namespace to bind
420+
kvPersist: "./kv-data", // Persist KV data (to optional path)
421+
422+
durableObjects: {
423+
// Durable Object to bind
424+
TEST_OBJECT: "TestObject", // className
425+
API_OBJECT: { className: "ApiObject", scriptName: "api" },
426+
},
427+
durableObjectsPersist: "./durable-objects-data", // Persist Durable Object data (to optional path)
428+
429+
cache: false, // Enable default/named caches (enabled by default)
430+
cachePersist: "./cache-data", // Persist cached data (to optional path)
431+
cacheWarnUsage: true, // Warn on cache usage, for workers.dev subdomains
432+
433+
sitePath: "./site", // Path to serve Workers Site files from
434+
siteInclude: ["**/*.html", "**/*.css", "**/*.js"], // Glob pattern of site files to serve
435+
siteExclude: ["node_modules"], // Glob pattern of site files not to serve
436+
437+
envPath: true, // Load environment variables from .env
438+
envPath: "./env.custom", // ...or custom .env path
439+
440+
bindings: { SECRET: "sssh" }, // Binds variable/secret to environment
441+
globals: { LOG: () => console.log("magic") }, // Binds variable/secret to global scope
442+
wasmBindings: { ADD_MODULE: "./add.wasm" }, // WASM module to bind
443+
});
444+
445+
await mf.reload(); // Reload scripts and configuration files
446+
447+
await mf.setOptions({ kvNamespaces: ["TEST_NAMESPACE2"] }); // Apply options and reload
448+
449+
const globalScope = await mf.getGlobalScope(); // Get sandbox's global scope
450+
const bindings = await mf.getBindings(); // Get bindings (KV/Durable Object namespaces, variables, etc)
451+
452+
const exports = await mf.getModuleExports(); // Get exports from entry module
453+
454+
const mount = await mf.getMount("api"); // Get mounted MiniflareCore instance
455+
await mount.getBindings();
456+
457+
// Dispatch "fetch" event to worker
458+
const res = await mf.dispatchFetch("http://localhost:8787/", {
459+
headers: { Authorization: "Bearer ..." },
460+
});
461+
const text = await res.text();
462+
const resWaitUntil = await res.waitUntil(); // Get `waitUntil`ed promises
463+
464+
// Dispatch "scheduled" event to worker
465+
const waitUntil = await mf.dispatchScheduled(Date.now(), "30 * * * *");
466+
467+
const TEST_NAMESPACE = await mf.getKVNamespace("TEST_NAMESPACE");
468+
469+
const caches = await mf.getCaches(); // Get global `CacheStorage` instance
470+
const defaultCache = caches.default;
471+
const namedCache = await caches.open("name");
472+
473+
// Get Durable Object namespace and storage for ID
474+
const TEST_OBJECT = await mf.getDurableObjectNamespace("TEST_OBJECT");
475+
const id = TEST_OBJECT.newUniqueId();
476+
const storage = await mf.getDurableObjectStorage(id);
477+
478+
const server = await mf.createServer(); // Create http.Server instance
479+
server.listen(8787, () => {});
480+
481+
const server2 = await mf.startServer(); // Create and start http.Server instance
482+
server2.close();
483+
484+
const scheduler = await mf.startScheduler(); // Start CRON scheduler
485+
await scheduler.dispose();
486+
487+
await mf.dispose(); // Cleanup storage database connections and watcher
488+
```

docs/cli.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ Core Options:
204204
-d, --debug Enable debug logging [boolean]
205205
-V, --verbose Enable verbose logging [boolean]
206206
--(no-)update-check Enable update checker (enabled by default) [boolean]
207-
--root Path to resolve default config files relative [string]
208-
to
209-
--mount Mount additional named workers [array:NAME=PATH]
207+
--root Path to resolve files relative to [string]
208+
--mount Mount additional named workers [array:NAME=PATH[@ENV]]
210209
211210
HTTP Options:
212211
-H, --host Host for HTTP(S) server to listen on [string]
@@ -235,7 +234,7 @@ KV Options:
235234
--kv-persist Persist KV data (to optional path) [boolean/string]
236235
237236
Durable Objects Options:
238-
-o, --do Durable Object to bind [array:NAME=CLASS]
237+
-o, --do Durable Object to bind [array:NAME=CLASS[@MOUNT]]
239238
--do-persist Persist Durable Object data (to [boolean/string]
240239
optional path)
241240

docs/durable-objects.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ export default {
196196

197197
Miniflare can be configured to load `TestObject` from the `api` worker with:
198198

199+
```shell
200+
$ miniflare --mount api=./api --do TEST_OBJECT=TestObject@api
201+
```
202+
199203
```toml
200204
# wrangler.toml
201205
[durable_objects]
@@ -217,8 +221,6 @@ const mf = new Miniflare({
217221
});
218222
```
219223

220-
Note it's not possible to set `script_name` via the CLI.
221-
222224
## Internal Details
223225

224226
Transactional semantics only hold within the same Miniflare instance. Therefore,

docs/fetch.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ const mf = new Miniflare({
127127
`,
128128
upstream: "https://miniflare.dev",
129129
});
130-
// MUST use same upstream URL when dispatching
130+
// If you don't use the same upstream URL when dispatching, Miniflare will
131+
// rewrite it to match the upstream
131132
const res = await mf.dispatchFetch("https://miniflare.dev/fetch.html");
132133
console.log(await res.text()); // Source code of this page
133134
```

docs/migrating.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const mf = new Miniflare({
109109
```
110110

111111
See
112-
[📌 Durable Objects](http://localhost:3000/durable-objects.html#using-a-class-exported-by-another-script)
112+
[📌 Durable Objects](/durable-objects.html#using-a-class-exported-by-another-script)
113113
for more details.
114114

115115
### Install the optional `@miniflare/storage-redis` package

0 commit comments

Comments
 (0)