🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

lev-react-renderer

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lev-react-renderer

A React rendering middleware for Restify

1.1.1
latest
Source
npm
Version published
Maintainers
3
Created
Source

React rendering middleware for Restify

A Restify middleware that provides a res.render method for sending HTML responses based on a React component. styled-components is supported.

The rendering is done server-side (SSR) but isomorphic / client-side rendering is also supported by providing a link to your bundle.

Installation

npm install --save lev-react-renderer

Usage

'use strict';

const restify = require('restify');
const reactRenderer = require('lev-react-renderer');

const formatText = restify.formatters['text/plain; q=0.3'];

const httpd = restify.createServer({
  formatters: {
    'text/html': formatText
  }
});

httpd.use(reactRenderer());

httpd.get('/', (req, res, next) => {
  res.render(YourApp, yourProps);
});

httpd.listen(8080, '0.0.0.0', () => {
  log.info('%s listening at %s', httpd.name, httpd.url);
});

Isomorphic rendering

In addition to Server-Side Rendering (SSR) this library supports 'hydrating' your application on the client-side. To do so, simply provide the location of your 'bundle' when creating the middleware. e.g.

httpd.use(reactRenderer({
  bundle: 'public/bundle.js'
}));

The bundle should call the hydrate function with the same component you are passing to res.render(). e.g.

import { hydrate } from 'lev-react-renderer';
import { YourApp } from './YourApp';

hydrate(YourApp);

Working on this repository

To test changes to this repository simply run:

make test

FAQs

Package last updated on 11 Feb 2022

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