@d1testflare/sites
v2.9.0
Published
Workers Sites module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers
Downloads
78
Maintainers
Readme
@d1testflare/sites
Workers Sites module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers. See 🌐 Workers Sites for more details.
Example
import { CorePlugin, MiniflareCore } from "@d1testflare/core";
import { VMScriptRunner } from "@d1testflare/runner-vm";
import { Log, LogLevel } from "@d1testflare/shared";
import { SitesPlugin } from "@d1testflare/sites";
export class BadStorageFactory {
storage() {
throw new Error("This example shouldn't need storage!");
}
}
const plugins = { CorePlugin, SitesPlugin };
const ctx = {
log: new Log(LogLevel.INFO),
storageFactory: new BadStorageFactory(),
scriptRunner: new VMScriptRunner(),
};
const mf = new MiniflareCore(plugins, ctx, {
modules: true,
script: `export default {
async fetch(request, env) {
const url = new URL(request.url);
const pathname = url.pathname.substring(1);
return new Response(await env.__STATIC_CONTENT.get(pathname));
}
}`,
sitePath: "./public",
});
// Assuming ./public/test.txt contains the text `test`
const res = await mf.dispatchFetch("http://localhost/test.txt");
console.log(await res.text()); // test