apeman-middleware-react
v1.0.2
Published
apeman middleware package for react
Downloads
5
Readme
apeman-middleware-react
apeman middleware package for react
Installation
$ npm install apeman-middleware-react --save
Usage
create an middleware instance and attach to server settings like $api
of apeman projects.
Apemanfile.js
/** This is an example Apemanfile to use apeman-middleware-react */
'use strict'
const co = require('co')
module.exports = {
$pkg: { /* ... */ },
$ui: {
/* ... */
':page_name': co.wrap(function * renderPage (ctx, next) {
let { params } = ctx
let PageComponent = require('./example-page-components')[ params[ 'page_name' ] ]
if (PageComponent) {
let props = { /* ... */ }
// Use `.react` method to render react static markup to provided by `apeman-middleware-react` package.
ctx.react(PageComponent, props)
} else {
yield next()
}
}),
$middlewares: [
require('apeman-middleware-react')({})
]
}
}
Signature
apemanMiddlewareReact(options) -> function
Create an middleware function
Args
| Name | Type | Default | Description | | --- | ---- | --- | --- | | options | Object | {} | Optional settings |
License
This software is released under the MIT License.