npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-page-middleware

v0.4.1

Published

Connect middleware for rendering pages with React JavaScript Library.

Downloads

7

Readme


This project is not actively maintained. Proceed at your own risk!


react-page-middleware

Middleware for building full page apps using React, JSX, and CommonJS.

If you want to get started with server rendered React apps, go directly to react-page. This project is the implementation of the router/server-side-page-assembler/packager.

###Features

  • Server-side JavaScript rendering of pages/apps using React.
  • Pages rendered on server, seamlessly brought to life in the browser.
  • No special glue code to write - "Just works" on client/server.
  • CommonJS + React + optional JSX.

###Requirements

- node (a more recent version)
- npm

###Install

Let npm do all the installing - just create a directory structure anywhere as follows:

yourProject/
 ├── package.json              # Add npm dependencies here.
 ├── server.js                 # Start web server with `node server.js`
 └── src                       # All your application JS.
     ├── index.js              # localhost:8080/index.html routed here
     └── pages                 # Configure the page root using pageRouteRoot
         └── about.js          # localhost:8080/about.html

List your dependencies in package.json:

// Shows how to depend on bleeding edge versions. One niceness of
// `react-page-middleware`, is depending on the main React repo as
// `require('React')` Not all JS packagers understand the pure git repo for
// React.
"dependencies": {
  "React": "git://github.com/facebook/react.git",
  "react-page-middleware": "git://github.com/facebook/react-page-middleware.git",
  "connect": "2.8.3"
},

Download your project's dependencies:

cd yourProject
npm install

Create a server.js file that requires react-page-middleware, and set the proper directory search paths and routing paths.

var reactMiddleware = require('react-page-middleware');
var REACT_LOCATION = __dirname + '/node_modules/react-tools/src';
var ROOT_DIR = __dirname;
var app = connect()
  .use(reactMiddleware.provide({
    logTiming: true,
    pageRouteRoot: ROOT_DIR,           // URLs based in this directory
    useSourceMaps: true,                // Generate client source maps.
    projectRoot: ROOT_DIR,          // Search for sources from
    ignorePaths: function(p) {          // Additional filtering
      return p.indexOf('__tests__') !== -1;
    }
  }))
  .use(connect['static'](__dirname + '/src/static_files'));
http.createServer(app).listen(8080);

Run the server and open index.html:

node server open http://localhost:8080/index.html

The react-page project has a much more thorough explanation of the motivation and features.

JavaScript-centric Routing And Page Rendering For JavaScript.

The default router is JavaScript-centric. You simply specify the path to the JS component you want to use to render the entire page. react-page for more information about the routing.

Source Maps

react-page-middleware has them.

Run and Build on the Fly

Just hit your browser's refresh button to run an always-up-to-date version of your app.

  • Dynamically packages/compiles your app on each server request.

Purpose

react-page-middleware is a rapid development environment where you can experiment with entirely new ways of building production web apps powered by React. It provides a common environment that allows sharing of modules client/server architecture prototypes.

In order to use this technology in a production environment, you would need to audit and verify that the server rendering strategy is safe and suitable for your purposes.

  • In particular, you would want to ensure that a proper server sandbox is enforced. However, react-page does run your UI rendering code inside of contextify as a preliminary sandbox.

  • The packaging/transforming features of react-page would not be needed in a production environment where the packages can be prebuilt once, stored in a CDN and not be repackaged on the fly, but the server rendering feature is very compelling for production environments where page load performance is of great concern.

  • Among other things, additional connect middleware should be added to prevent stack traces from showing up in the client.