1.3.0
done-ssr 1.3.0 is a major milestone in this project. It represents a refactor of almost the entire codebase while remaining API compatible. The refactor was to enable the new, lower-level, zones API as described before.
Zones API
The new Zones API exposes plugins that can be used with can-zone to handle rendering in a more customizable way. For example, there are 2 DOM implementations to choose from; can-simple-dom (the default used by done-ssr) and can-zone-jsdom.
A few of the zones included are:
- requests: a Zone that handles rerouting APIs to the local server;
/api/todosbecomeshttp://10.0.0.1:8080/api/todos. - cookies: Handles copying over cookies from an HTTP Request into the local DOM's
document.cookiesstring. - push-images: A Zone that will estable a PUSH Promise when on an HTTP/2 server.
Using the Zones API allows you to do server-rendering in your own HTTP handlers; without using done-ssr to take over a request. An example usage is:
var Zone = require("can-zone");
var requests = require("done-ssr/zones/requests");
var dom = require("can-zone-jsdom")
var pushFetch = require("done-ssr/zones/push-fetch");
var pushImages = require("done-ssr/zones/push-images");
var app = require("./app");
require("spdy").createServer(options, async function(request, response){
var zone = new Zone([
// Overrides XHR, fetch
requests(request),
// Sets up a DOM
dom(request),
pushFetch(response),
pushImages(response)
]);
let {html} = await zone.run(app);
// The full HTML after all async tasks are complete
response.end(html);
});