kadirahq / flow-router

Carefully Designed Client Side Router for Meteor
MIT License
1.09k stars 195 forks source link

Server side rendering stopped working, may be related to createCountainer #701

Open bensventures opened 7 years ago

bensventures commented 7 years ago

I know this is going to be a long shot but here is my problem. I am using FlowRouter_SSR with react-mounter to manage routing in the application. I include my routes also on the server side to have the server side rendering working on first page load.

This was working fine up to a few weeks / days ago (not really sure when). Right now everything is routing fine but nothing is server rendered. I have no error in the logs / console.

I have seen in a thread on the Meteor forum that FlowRouter_SSR doesn't work when you use the new createContainer way of passing the data to your containers.

I understand this is kind of a dead project but it would be great if we could collectively resolve some pending issues. I've tracked the rendering flow on the server side through react-mounter and everything seems to be working find, up to the point where react-mounter passes the generated html to FlowRouter:

// server.js line 44 react-mounter package
ssrContext.setHtml(html);

How would I go about debugging the FlowRouter side of things. I have naively tried putting some consle.logs in the FlowRouter_SSR atmosphere package but that breaks the server restart. I have 0 experience creating meteor packages.

Aur0r commented 7 years ago

The cause for SSR not working currently is if you are using Meteor 1.4.2 to be precise the webapp package (which also blaze needs in 1.4.2). For further information see https://github.com/meteor/meteor/issues/7992.

Till the solution is implemented in Flowrouter I have locked the following package versions in the packages file: accounts-base@=1.2.13 accounts-password@=1.3.0 blaze@=2.2.0 webapp@=1.3.11_1

And the release version is set to: METEOR@1.4.1.3

And then I am updating the packages via "meteor update --packages-only" for now.

However this is just a temporary workaround and I would like to see a fix in Flowrouter too so one can update to Meteor 1.4.2+ again.

bensventures commented 7 years ago

@Aur0r This is fixed for me with this fork: https://github.com/bensventures/flow-router

achtan commented 7 years ago

@bensventures hi im using your fork, but im getting document is not defined error

EDIT: my bad, its working fine!

achtan commented 7 years ago

@bensventures how do u redirect non-www to www url? if i use Picker like this:

import {Picker} from 'meteor/meteorhacks:picker'

Picker.route('/(.*)', function(params, req, res, next) {
  console.log('picker', req.url)
  if (req.headers.host === 'domain.sk') {
    const redirectTo = 'http://www.domain.sk' + req.url;
    if (res) {res.writeHead(301, {'Location': redirectTo}); res.end(); }return;
  }
  next();
});

then SSR stops working, (without that picker code above, ssr is working fine)

bensventures commented 7 years ago

I've always had Meteor behind Nginx, that's where I am doing the redirect. I think it makes sense to have the web server handle that.