Middleware of koa server. See more information in code and here.
Render html
with react
and nunjucks
. If you need to use radium
. You will get radiumConfig
as props
to your component
.
nunjucks
react
react-dom
component
: This component is used to render to the template.options(default: {})
root(default: './views')
: This is the folder of the templates which is fornunjucks
.renderKey(default: 'content')
: This is the variable in template which will be replace withcomponent
.template(default: 'template.html'
): This is the template of the html.- You can add other variables for your template.
import reactRender from 'cat-middleware/lib/koa-react-render';
...
app.use(reactRender(
<div>render react</div>
));
...
Use to check the authentication. You must have user
in ctx.state
and authentication
in user
. You can use koa-passport
to do this.
- Arguments
authentication_levels(default: {})
: This is used to check the authentication. For example, it will be like{none: 0, user: 1, superuser: 999}
.env(default: true)
: If this is false, this middleware will not check the authentication. Remeber to use this withprocess.env.NODE_ENV
.
- Arguments
authentication(default: 'none')
: Use to set authentication inurl
.redirect(default: '/')
: Redirect to the url when user dose not pass the authentication.
import authentication from 'cat-middleware/lib/koa-authentication';
...
app.use(authentication.configure({
none: 0,
user: 1
}, process.env.NODE_ENV === 'production'));
...
router.get(
'/authentication/',
authentication.set('user', '/authentication/fail/'), ctx => {
// do something here
}
);
...
Use to get the data from fetch
with react-relay
.
babel-polyfill
fetch-everywhere
react-relay
link
query
variables
import relayData from 'cat-middleware/lib/koa-relay-data';
...
app.use(relayData(
link, graphql`
query relayData {
data {
key
}
}
`
));
...
// Then you can get the data `graphql_data` in your `ctx`.
MIT © hsuting