0.6.3 • Published 1 year ago

@dom-preview/server v0.6.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

@dom-preview/server

This is the server component of dom-preview.

Usage

import { runDomPreviewServer, DomPreviewCreate } from "@dom-preview/server";

// Put your frontend files into ./static-files
const { shutdown } = await runDomPreviewServer({
  // Listening port
  port: 5007,
  // Deliver the web-frontend for "dom-preview"
  staticFilesDir: "./static-files",
  // You can proxy requests to the running dev-server (e.g. vite) to retrieve assets
  // For security reasons, only localhost is allowed for now
  proxyUnknownRequestsTo: `http://localhost:5173`,
});

process.on("SIGINT", () => {
  shutdown().catch(console.error);
});

In the browser:

const eventSource = new EventSource(
  "http://localhost:5007/api/stream/previews",
);
eventSource.addEventListener("preview-added", (event) => {
  console.log(JSON.parse(event.data));
});

In the unit test:

await fetch("http://localhost:5007/previews", {
  method: "POST",
  body: JSON.stringify({
    alias: "some alias name for the screenshot (optional)",
    context: "the name of the current test",
    html: document.documentElement.outerHTML, // e.g. `<html><body>Hello HTML: <input type="text"></body></html>`,
    inputValues: ["input field value"],
    timestamp: Date.now(),
  } satisfies DomPreviewCreate),
});
0.6.3

1 year ago

0.6.2

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.2

1 year ago