4.3.1 • Published 2 years ago

@vrbo/catalyst-render v4.3.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

@vrbo/catalyst-render

NPM Version npm.io Dependency Status NPM Downloads

Introduction

A Hapi.js plugin that works with the catalyst-server to aid in server-side rendering using Handlebars and React. It allows you to relate a Handlebars template and a React component to a route. This route will automatically be registered with the server and will decorate request.pre.component with the react component and the request.pre.template with the template. It will also register @hapi/vision and server views with Handlebars rendering for the page scaffolding

Usage

Install:

npm install @vrbo/catalyst-render

Register the plugin in the application's manifest:

...
"register": {
    "catalyst-render": {
        "plugin": "require:@vrbo/catalyst-render",
        "options": {
            "routes": [{
                "route": "require:./routes/application.js",
                "component": "require:../components/App/server.js",
                "template": "./templates/welcome.hbs"
            }]
        }
    }
}
...

The require:./routes/application.js points to a route file that exports a Hapi.js route object and will look something like this (with a very basic render):

module.exports = {
    method: 'GET',
    path: '/',
    options: {
        handler(request, h){
            const template = request.pre.template;
            const Component = request.pre.component;
            const body = ReactDOMServer.renderToString(<Component/>);
            return h.view(template, { body })
        },
        id: 'root'
    }
}

API

Register the plugin server.register(server, options)

ParamTypeDescription
serverobjectHapi.js server
optionsobjectOverriding options
options.routesarrayA list of route objects to register on server.
options.viewsOptionsobjectOptions to add to (or override) when on server.views method is called for adding things like partials ,, layouts, helpers and others.
options.visionOptionsobjectProxy for options when registering @hapi/vision.
options.resolveAssetHelperobjectA Handlebars helper to help resolve static assets, as in publishing to a CDN.
options.resolveAssetHelper.namestringName of helper.
options.resolveAssetHelper.helperfunctionHelper function.

Route

This is an object for registering routes, React components, and templates

PropertyTypeDescription
routeobjectHapi.js route object to register on server.
componentobjectA React component to render. Available as request.pre.component in handler in above route.
templatearrayA Handlebars template to use to render page scaffold. Available as request.pre.template in handler in above route.

Further Reading

4.3.1

2 years ago

4.3.0

2 years ago

4.1.8

3 years ago

4.1.7

3 years ago

4.1.6

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.4

4 years ago

4.1.3

4 years ago

4.1.5

4 years ago

4.0.0

4 years ago

3.0.0

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago