Socket
Socket
Sign inDemoInstall

backpage

Package Overview
Dependencies
238
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    backpage

Naive static HTML streaming based on React for Node.js CLI applications.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

NPM version Repository package.json version MIT License Discord

BackPage

Naive static HTML streaming based on React for Node.js CLI applications.

How does it work?

BackPage renders your React application to HTML and streams updates (static HTML snapshots) to your browser.

It is designed for really simple GUI as a complementary to text logs, so user interaction is neither supported nor its goal.

Features

  • Stream static HTML from React rendering.
  • Send notification to browser.
  • Public URL via backpage.cloud.

Installation

npm install react backpage

Basic Usage

main.tsx

import {BackPage} from 'backpage';
import React from 'react';

import {App} from './app.js';

const page = new BackPage();

page.render(<App />);

// Print page information including URL.
page.guide();

// Send notification to browser (if connected).
page.notify('Hello BackPage!');

app.tsx

import React, {useState, useEffect} from 'react';

export const App = () => {
  const [count, setCount] = useState(0);

  useEffect(() => {
    const timer = setInterval(
      setCount(count => count + 1),
      1000,
    );

    return () => clearInterval(timer);
  }, []);

  return <div>Count: {count}</div>;
};

Public URL

By specifying a UUID as token, you can get a public URL from backpage.cloud:

import {BackPage, getPersistentToken} from 'backpage';

const page = new BackPage({
  // You can also use any random UUID for temporary page.
  token: getPersistentToken(),
  // Different pages can be setup using the same token with different names.
  name: 'project-name',
});

page.guide();

Note: backpage.cloud may introduce payments for significant network traffic to cover the expense in the future.

Notify Fallback

You can get notified if no browser is connected or the notification is not clicked within the timeout.

const page = new BackPage({
  notify: {
    timeout: 30_000,
    fallback: notification => {
      // Handle the notification manually.

      // You can also return a webhook URL or request options to initiate an
      // HTTP request.
      return 'https://some.webhook/';
    },
  },
});

page.notify('Hello BackPage!');

Built-in Components

<Title />

Setting the title of the page.

page.render(
  <>
    <Title>Awesome Page</Title>
    <div>Hello BackPage!</div>
  </>,
);

<Style />

Add a <style /> tag to the page with content loaded from src.

const App = () => (
  <>
    <Style src={STYLE_PATH} />
    <div>Hello BackPage!</div>
  </>
);

<Console />

Intercepts console outputs using patch-console.

const App = () => (
  <>
    <h2>Logs</h2>
    <Console />
  </>
);

License

MIT License.

FAQs

Last updated on 14 Jan 2024

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc