Open ryuapp opened 6 days ago
It works for me using both node_modules
and npm:
specifiers and a global module directory:
$ npm install miniflare
$ cat main.ts
import { Miniflare } from "miniflare";
// Create a new Miniflare instance, starting a workerd server
const mf = new Miniflare({
script: `addEventListener("fetch", (event) => {
event.respondWith(new Response("Hello Miniflare!"));
})`,
});
// Send a request to the workerd server, the host is ignored
const response = await mf.dispatchFetch("http://localhost:8787/");
console.log(await response.text()); // Hello Miniflare!
// Cleanup Miniflare, shutting down the workerd server
await mf.dispose();
$ deno -V
deno 1.46.3
$ deno run -A main.ts
Hello Miniflare!
$ cat main.ts
import { Miniflare } from "npm:miniflare";
// Create a new Miniflare instance, starting a workerd server
const mf = new Miniflare({
script: `addEventListener("fetch", (event) => {
event.respondWith(new Response("Hello Miniflare!"));
})`,
});
// Send a request to the workerd server, the host is ignored
const response = await mf.dispatchFetch("http://localhost:8787/");
console.log(await response.text()); // Hello Miniflare!
// Cleanup Miniflare, shutting down the workerd server
await mf.dispose();
$ deno -V
deno 1.46.3
$ deno run -A main.ts
Hello Miniflare!
Maybe this only happens on Windows?
Maybe this only happens on Windows?
I guess so. There were no errors when I ran it on WSL.
Confirmed it reproduces on windows. The immediate issue is https://github.com/denoland/deno/issues/25604, but supporting this will also require fixing https://github.com/denoland/deno/issues/23524
Miniflare is a simulator for developing and testing Cloudflare Workers, powered by workerd. This library is used by many frameworks as Cloudflare adapter. e.g.) SvelteKit, Astro, HonoX
Currently, the example written in README does not work either.
Related: https://github.com/denoland/deno/issues/25513