Skip to content

marshallswain/done-ssr

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

304 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status npm version

done-ssr

Server-side rendering for DoneJS.

Usage

done-ssr takes a system 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:

License

MIT

About

Server Side Rendering for DoneJS

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 99.3%
  • Other 0.7%