@d1testflare/sites
TypeScript icon, indicating that this package has built-in type declarations

2.9.0 • Public • Published

@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

Package Sidebar

Install

npm i @d1testflare/sites

Weekly Downloads

5

Version

2.9.0

License

MIT

Unpacked Size

14.4 kB

Total Files

5

Last publish

Collaborators

  • oconnorct1