Meteor + React + SSR

So I recently came across this github repository (https://github.com/ssr-server/ssr) after asking about SSR here. It looks to be a good way to do SSR in Meteor using React+Redux+React-Router.

I noticed that it’s using Express and that got me to thinking. Is there currently a way to “hijack” Meteor’s main.html file (The one produced by default in the client directory) with Express such that you could then use .ejs (or whatever template) to render it, subsequently passing it back off to Meteor to be used as it normally would?

I know you can use Express middleware with Meteor (I’ve never done it) but I’m wondering if anyone’s done it before or could possibly provide some insight as to how it could be done.

Actually, it’s pretty simple. Meteor provides a webapp package which expose a connect middleware. Express is the de facto standard for connect middleware. Once Express is setup on webapp, you basically could use every kind of template engine that render to a string, being Ejs, Blase, Vue, Angular2, Jade/pug, React, Preact, Inferno or anything else one could think of.

By the way, Ejs template are pretty efficient. One of the point of our package is to transform JSX based component into some kind of Ejs template. For JSX based templating, the renderToString / renderToStaticMarkup are often really slow and does not allow time slicing for streaming and performant multiplexing. Though that, for the moment, we have a very neat and efficient TTL caching, which is great most of the time, it would fail on high dynamic web site with a huge spread of interests from it’s users. With data caching (we do it already) and component caching, even these kind of sites would render within few ms and could become streamable.

2 Likes