Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@dom-preview/server

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dom-preview/server

The live-server of the dom-preview package

latest
Source
npmnpm
Version
0.6.3
Version published
Maintainers
0
Created
Source

@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),
});

FAQs

Package last updated on 28 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts