@dom-preview/server
This is the server component of dom-preview.
Usage
import { runDomPreviewServer, DomPreviewCreate } from "@dom-preview/server";
const { shutdown } = await runDomPreviewServer({
port: 5007,
staticFilesDir: "./static-files",
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,
inputValues: ["input field value"],
timestamp: Date.now(),
} satisfies DomPreviewCreate),
});