New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-scripts-ssr

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-scripts-ssr

Create React apps with server-side rendering (SSR) with no configuration

latest
Source
npmnpm
Version
0.1.11
Version published
Maintainers
1
Created
Source

react-scripts-ssr

Create React apps with server-side rendering (SSR) with no configuration

Installation

npm install react-scripts-ssr --save-dev

Getting started

Steps

Step 1

In the scripts section of your package.json:

  • Replace "start": "react-scripts start" with "start": "react-scripts-ssr start",
  • Add "build-server": "react-scripts-ssr build-server",

Step 2

  • npm install express --save
  • Create the following file in src/server.js
const React = require("react");
const express = require("express");
const { createSSRMiddleware } = require("react-scripts-ssr");
const { renderToString } = require("react-dom/server");
import App from "./App";

const server = express();

server.use(
  createSSRMiddleware((req, res, next) => {
    const body = renderToString(<App />);
    next({ body }, req, res);
  })
);

const PORT = process.env.REACT_APP_SERVER_SIDE_RENDERING_PORT || 8888;
server.listen(PORT, () => {
  console.log(`server running on port ${PORT}`);
});

You can edit the server.js file with your custom code and other middlewares.

Step 3

npm start

Caveats

It only works with Create React App version 2

FAQs

Package last updated on 26 Dec 2018

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