React Component Server
A small lib that wraps express to allow for simple serving of react components.
Usage
Creating Server
To create a new React Component Server call the create method
const ReactComponentServer = const componentServer = ReactComponentServer
Component Server Options
// pass an http server instead of creating a new one server: server // relative path to components dir componentsDir: './components' // relative path to templates dir templatesDir: './templates' // set of defaults to use defaults: // flag to create a browserify bundle of component bundle: true // default component component: './App.js' // ./components/App.js // default props to pass to component props: {} // the template for the component template: './template.js' // ./templates/template.js
Creating routes
componentServer// or you can just pass an ObjectcomponentServer// or just use defaultscomponentServer
Listening on Port
// pretty much a proxy for express's listen methodcomponentServer// or you could just listen with the passed express app
Browserify bundles
To allow your component to be ran both client and server side you can create a bundle for it. There is a bit more configuration but is worth it.
Specify route needs bundle
componentServer
next you will need to inject that bundle and start it in the layout. Here is a example of what a simple layout that includes a bundle would look like.
const React = const safeStringify = // util to strip <scripts>const template = { return <html> <body> <div id='app' dangerouslySetInnerHTML= __html: ComponentString /> <script src=metabundlePath /> <script dangerouslySetInnerHTML= __html: ` var React = require('react') var ReactDOM = require('react-dom') var App = require('') ReactDOM.render( React.createElement(App, ), document.getElementById('app') ); ` /> </body> </html> } moduleexports = template
What this project needs help with
- external cacheing of html, and bundles
- remove dependency on express
- catching more error states
- more test
- feedback!