Server Side Rendering for DoneJS
Switch branches/tags
0.14-legacy 1.x-legacy css-order debug-missing-head debug default-system-main depcache flake gh-pages greenkeeper/can-component-4.1.0 greenkeeper/can-component-4.1.1 greenkeeper/can-component-4.1.2 greenkeeper/can-component-4.1.3 greenkeeper/can-component-4.2.0 greenkeeper/can-component-4.2.1 greenkeeper/can-component-4.2.2 greenkeeper/can-component-4.2.3 greenkeeper/can-component-4.2.4 greenkeeper/can-component-4.3.0 greenkeeper/can-component-4.4.0 greenkeeper/can-component-4.4.2 greenkeeper/can-component-4.4.3 greenkeeper/can-component-4.4.4 greenkeeper/can-component-4.4.5 greenkeeper/can-component-4.4.6 greenkeeper/can-component-4.4.7 greenkeeper/can-component-pin-4.0.8 greenkeeper/can-component-pin-4.3.0 greenkeeper/can-component-pin-4.4.2 greenkeeper/can-define-2.2.5 greenkeeper/can-define-2.3.0 greenkeeper/can-define-2.3.1 greenkeeper/can-define-2.3.2 greenkeeper/can-define-2.3.3 greenkeeper/can-define-2.3.4 greenkeeper/can-define-2.3.5 greenkeeper/can-define-2.3.6 greenkeeper/can-define-2.3.7 greenkeeper/can-define-2.4.0 greenkeeper/can-define-2.5.0 greenkeeper/can-define-2.5.1 greenkeeper/can-define-2.5.2 greenkeeper/can-define-2.5.3 greenkeeper/can-define-2.5.4 greenkeeper/can-define-2.5.5 greenkeeper/can-define-2.6.0 greenkeeper/can-define-2.6.1 greenkeeper/can-define-2.6.2 greenkeeper/can-define-pin-1.0.17 greenkeeper/can-define-pin-1.0.24 greenkeeper/can-define-pin-2.2.4 greenkeeper/can-define-pin-2.2.5 greenkeeper/can-define-pin-2.5.3 greenkeeper/can-define-pin-2.5.12 greenkeeper/can-dom-mutate-1.3.0 greenkeeper/can-dom-mutate-1.3.1 greenkeeper/can-dom-mutate-1.3.2 greenkeeper/can-dom-mutate-1.3.3 greenkeeper/can-dom-mutate-1.3.4 greenkeeper/can-dom-mutate-1.3.5 greenkeeper/can-dom-mutate-pin-1.2.2 greenkeeper/can-fixture-2.1.0 greenkeeper/can-fixture-3.0.1 greenkeeper/can-fixture-3.0.2 greenkeeper/can-fixture-3.0.3 greenkeeper/can-fixture-3.0.4 greenkeeper/can-fixture-pin-2.0.3 greenkeeper/can-globals-0.4.0 greenkeeper/can-globals-0.4.1 greenkeeper/can-globals-1.0.0 greenkeeper/can-globals-1.1.0 greenkeeper/can-globals-1.1.1 greenkeeper/can-globals-1.2.0 greenkeeper/can-globals-pin-0.3.0 greenkeeper/can-globals-pin-1.0.1 greenkeeper/can-list-pin-3.0.4 greenkeeper/can-map-define-pin-3.0.6 greenkeeper/can-reflect-1.11.1 greenkeeper/can-reflect-1.12.0 greenkeeper/can-reflect-1.13.0 greenkeeper/can-reflect-1.13.1 greenkeeper/can-reflect-1.13.2 greenkeeper/can-reflect-1.16.0 greenkeeper/can-reflect-1.16.1 greenkeeper/can-reflect-1.16.2 greenkeeper/can-reflect-1.16.3 greenkeeper/can-reflect-1.16.4 greenkeeper/can-reflect-1.16.5 greenkeeper/can-reflect-1.16.6 greenkeeper/can-reflect-1.16.7 greenkeeper/can-reflect-1.17.0 greenkeeper/can-reflect-1.17.1 greenkeeper/can-reflect-1.17.2 greenkeeper/can-reflect-1.17.3 greenkeeper/can-reflect-1.17.4 greenkeeper/can-reflect-pin-1.11.0 greenkeeper/can-reflect-pin-1.15.2 greenkeeper/can-reflect-pin-1.16.1 greenkeeper/can-reflect-pin-1.17.1 greenkeeper/can-route-4.1.2 greenkeeper/can-route-4.2.0 greenkeeper/can-route-4.3.0 greenkeeper/can-route-4.3.1 greenkeeper/can-route-4.3.2 greenkeeper/can-route-4.3.3 greenkeeper/can-route-4.3.4 greenkeeper/can-route-4.3.5 greenkeeper/can-route-4.4.0 greenkeeper/can-route-4.4.1 greenkeeper/can-route-4.4.2 greenkeeper/can-route-4.4.3 greenkeeper/can-route-4.4.4 greenkeeper/can-route-4.4.5 greenkeeper/can-route-pin-3.0.9 greenkeeper/can-route-pin-3.0.10 greenkeeper/can-route-pin-4.1.1 greenkeeper/can-route-pin-4.3.0 greenkeeper/can-route-pin-4.3.12 greenkeeper/can-route-pin-4.4.1 greenkeeper/can-route-pushstate-4.0.5 greenkeeper/can-route-pushstate-4.1.0 greenkeeper/can-route-pushstate-4.1.1 greenkeeper/can-route-pushstate-5.0.0 greenkeeper/can-route-pushstate-5.0.1 greenkeeper/can-route-pushstate-5.0.2 greenkeeper/can-route-pushstate-5.0.3 greenkeeper/can-route-pushstate-5.0.4 greenkeeper/can-route-pushstate-5.0.5 greenkeeper/can-route-pushstate-5.0.6 greenkeeper/can-route-pushstate-5.0.7 greenkeeper/can-route-pushstate-5.0.8 greenkeeper/can-route-pushstate-5.0.9 greenkeeper/can-route-pushstate-pin-4.0.4 greenkeeper/can-stache-4.4.0 greenkeeper/can-stache-4.5.0 greenkeeper/can-stache-4.5.1 greenkeeper/can-stache-4.5.2 greenkeeper/can-stache-4.5.3 greenkeeper/can-stache-4.5.4 greenkeeper/can-stache-4.5.5 greenkeeper/can-stache-4.5.6 greenkeeper/can-stache-4.5.7 greenkeeper/can-stache-4.5.8 greenkeeper/can-stache-4.5.9 greenkeeper/can-stache-4.5.10 greenkeeper/can-stache-4.6.0 greenkeeper/can-stache-4.7.0 greenkeeper/can-stache-4.7.1 greenkeeper/can-stache-4.8.0 greenkeeper/can-stache-4.9.0 greenkeeper/can-stache-4.9.1 greenkeeper/can-stache-4.10.0 greenkeeper/can-stache-4.10.3 greenkeeper/can-stache-4.10.4 greenkeeper/can-stache-4.10.5 greenkeeper/can-stache-4.11.0 greenkeeper/can-stache-4.11.1 greenkeeper/can-stache-4.11.2 greenkeeper/can-stache-4.11.3 greenkeeper/can-stache-4.12.0 greenkeeper/can-stache-4.15.3 greenkeeper/can-stache-4.15.4 greenkeeper/can-stache-4.15.5 greenkeeper/can-stache-4.15.6 greenkeeper/can-stache-4.15.7 greenkeeper/can-stache-4.15.11 greenkeeper/can-stache-4.15.12 greenkeeper/can-stache-pin-3.0.24 greenkeeper/can-stache-pin-4.3.4 greenkeeper/can-stache-pin-4.10.0 greenkeeper/can-stache-pin-4.10.5 greenkeeper/can-stache-pin-4.15.2 greenkeeper/can-stache-pin-4.15.9 greenkeeper/can-util-pin-3.3.6 greenkeeper/can-util-pin-3.8.1 greenkeeper/documentjs-0.5.1 greenkeeper/documentjs-0.5.2 greenkeeper/documentjs-0.5.4 greenkeeper/documentjs-pin-0.5.0 greenkeeper/documentjs-pin-0.5.1 greenkeeper/dom-patch-2.1.6 greenkeeper/dom-patch-2.2.0 greenkeeper/dom-patch-pin-2.1.5 greenkeeper/dom-patch-pin-2.1.6 greenkeeper/done-autorender-2.5.1 greenkeeper/done-autorender-pin-2.5.0 greenkeeper/done-css-pin-3.0.0 greenkeeper/done-mutation-2.1.5 greenkeeper/done-mutation-pin-2.1.4 greenkeeper/es6-promise-4.2.0 greenkeeper/es6-promise-4.2.1 greenkeeper/es6-promise-4.2.2 greenkeeper/es6-promise-4.2.3 greenkeeper/es6-promise-4.2.4 greenkeeper/es6-promise-4.2.5 greenkeeper/es6-promise-pin-4.1.1 greenkeeper/es6-promise-pin-4.2.4 greenkeeper/ir-reattach-4.0.1 greenkeeper/ir-reattach-4.0.2 greenkeeper/ir-reattach-pin-4.0.0 greenkeeper/jquery-3.3.1 greenkeeper/jquery-pin-3.3.0 greenkeeper/jshint-2.9.6 greenkeeper/jshint-pin-2.9.5 greenkeeper/leakage-pin-0.3.0-beta greenkeeper/lru-cache-5.0.0 greenkeeper/lru-cache-5.0.1 greenkeeper/lru-cache-5.1.0 greenkeeper/lru-cache-5.1.1 greenkeeper/mime-types-2.1.19 greenkeeper/mime-types-pin-2.1.18 greenkeeper/nock-9.0.15 greenkeeper/nock-9.0.16 greenkeeper/nock-9.0.17 greenkeeper/nock-9.0.18 greenkeeper/nock-9.0.19 greenkeeper/nock-9.0.20 greenkeeper/nock-9.0.21 greenkeeper/nock-9.0.22 greenkeeper/nock-9.0.24 greenkeeper/nock-9.0.26 greenkeeper/nock-9.0.27 greenkeeper/nock-9.0.28 greenkeeper/nock-9.1.0 greenkeeper/nock-9.1.4 greenkeeper/nock-9.1.5 greenkeeper/nock-9.1.6 greenkeeper/nock-9.2.6 greenkeeper/nock-9.3.0 greenkeeper/nock-9.3.1 greenkeeper/nock-9.3.2 greenkeeper/nock-9.3.3 greenkeeper/nock-9.4.0 greenkeeper/nock-9.4.1 greenkeeper/nock-9.4.2 greenkeeper/nock-9.4.3 greenkeeper/nock-9.4.4 greenkeeper/nock-9.5.0 greenkeeper/nock-9.6.0 greenkeeper/nock-9.6.1 greenkeeper/nock-10.0.0 greenkeeper/nock-10.0.1 greenkeeper/nock-10.0.2 greenkeeper/nock-10.0.3 greenkeeper/nock-10.0.4 greenkeeper/nock-pin-9.0.14 greenkeeper/nock-pin-9.0.20 greenkeeper/nock-pin-9.0.25 greenkeeper/nock-pin-9.0.27 greenkeeper/nock-pin-9.1.3 greenkeeper/nock-pin-9.1.4 greenkeeper/nock-pin-9.2.5 greenkeeper/nock-pin-9.2.6 greenkeeper/nock-pin-9.4.3 greenkeeper/node-fetch-2.2.0 greenkeeper/node-fetch-pin-2.1.2 greenkeeper/steal-css-pin-1.2.2 greenkeeper/steal-pin-1.4.5 greenkeeper/steal-stache-4.1.1 greenkeeper/steal-stache-4.1.2 greenkeeper/steal-stache-pin-3.0.5 greenkeeper/steal-stache-pin-4.1.0 greenkeeper/text-encoding-0.7.0 greenkeeper/through2-2.0.4 greenkeeper/through2-2.0.5 greenkeeper/through2-3.0.0 greenkeeper/through2-pin-2.0.3 greenkeeper/uglify-js-3.3.25 greenkeeper/uglify-js-3.3.26 greenkeeper/uglify-js-3.3.27 greenkeeper/uglify-js-3.3.28 greenkeeper/uglify-js-3.4.0 greenkeeper/uglify-js-3.4.1 greenkeeper/uglify-js-3.4.2 greenkeeper/uglify-js-3.4.3 greenkeeper/uglify-js-3.4.4 greenkeeper/uglify-js-3.4.5 greenkeeper/uglify-js-3.4.6 greenkeeper/uglify-js-3.4.7 greenkeeper/uglify-js-pin-3.3.24 greenkeeper/uglify-js-pin-3.3.25 greenkeeper/uglify-js-pin-3.4.5 greenkeeper/websocket-1.0.25 greenkeeper/websocket-pin-1.0.24 h1 h2-api head-insert-before-null instr ir-take2 lr master mionr no-import override prior provide relative-css steal-exec supercache x zones
Nothing to show
Clone or download
Latest commit 8e35c05 Dec 10, 2018

README.md

Build Status npm version

done-ssr

Greenkeeper badge

Server-side rendering for DoneJS.

Install

npm install done-ssr --save

Usage

done-ssr takes a steal configuration object (the same object used by steal-tools to configure building) and returns a function that will render requests.

Pass your request into the render function and pipe the resulting stream into the response.

var http = require("http");
var ssr = require("done-ssr");
var render = ssr();

var server = http.createServer(function(request, response){
	render(request).pipe(response);
});

server.listen(8080);

Your app

done-ssr expect's your project's main to export a function that renders based on the request parameter. This will work with any module format supported by Steal.

var ViewModel = can.Map.extend( { ... });

module.exports = function(request){
  var params = can.route.deparam(location.pathname);
  var viewModel = new ViewModel(params);

  // Do whatever is needed to render
};

The request parameter is the raw Node request object so you can do things like get request headers if needed.

Additionally the location object is set globally so you can use it like you would in a browser window.

More can be found in the main module docs.

Express Middleware and Development Server

As of 0.12 can-ssr was renamed to done-ssr. The Express middleware and can-serve functionality were moved to their own projects:

API

ssr(steal, options) -> render

The ssr function contains two arguments, one for the steal object and one is an options object:

steal

Configuration options that are a StealConfig. This is the same object that is passed into steal-tools to configure the loader for building.

options

timeout : 5000

Specify a timeout in milliseconds for how long should be waited before returning whatever HTML has already been rendered. Defaults to 5000

auth: {cookie, domains}

An object for enabling JavaScript Web Tokens (JWT) support for XHR requests made by the SSR server. Must contain both of the following values:

  • cookie: A string representing the cookie name where the SSR server can look to find a JWT token. That token gets applied as the "Bearer" token in the authorization header of every outgoing XHR.

For example, if the SSR server receives a cookie like feathers-jwt=<token>;, and the authCookie option is set to "feathers-jwt", outgoing requests from the SSR server will have an authorization header of Bearer <token>

  • domains: An array of domain names to which the JWT token will be sent. Any domains not in this list will not receive the JWT token.
debug : false

Specify to turn on debug mode when used in conjunction with timeout. If rendering times out debugging information will be attached to a modal window in the document. For this reason you only want to use the debug option during development.

debug output

strategy: 'safe'

Specify the rendering strategy. In done-ssr 1.1.0 the new incremental rendering strategy was added which works by returning initial HTML immediately and incrementally updating the DOM in the client. To enable incremental rendering set this option:

var render = ssr(steal, {
  strategy: "incremental"
});

Note: the DONE_SSR_DEBUG environment variable can be used if you need to debug what is happening during incremental rendering reattachment. This provides unminified reattachment code. Set it to any value to enable the debugging. export DONE_SSR_DEBUG=1.

render(request)

The render function is returned from the call to ssr and is what used to render requests. It returns a readable stream that can be piped into other streams, using the response stream.

render(request).pipe(response);

You can use request/response streams from servers created with require("http"), or Express and probably most other Node servers.

License

MIT