From aa54354002c1f1fe19f2efaa461c184e52b427c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20R=C3=BCtten?= Date: Thu, 7 Jul 2016 12:15:21 +0200 Subject: [PATCH 1/4] Added request object to FlowRouter action parameters --- server/route.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/route.js b/server/route.js index 28d68a5..f27efe7 100644 --- a/server/route.js +++ b/server/route.js @@ -74,7 +74,7 @@ Route = class extends SharedRoute { } if (self.options.action) { - self.options.action(routeContext.params, routeContext.queryParams); + self.options.action(routeContext.params, routeContext.queryParams, req); } } catch (ex) { logger.error(`Error when doing SSR. path:${req.url}: ${ex.message}`); From 2936bde42c97db0132be1e60167c7341ff81e5a1 Mon Sep 17 00:00:00 2001 From: Stephan Georg Date: Fri, 22 Jul 2016 13:41:47 +0200 Subject: [PATCH 2/4] Fixed SSR for dotted urls --- server/route.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/server/route.js b/server/route.js index f27efe7..4ad84b8 100644 --- a/server/route.js +++ b/server/route.js @@ -153,20 +153,16 @@ Route = class extends SharedRoute { _isHtmlPage(url) { const pathname = Url.parse(url).pathname; const ext = pathname.split('.').slice(1).join('.'); - - // if there is no extention, yes that's a html page + // if there is no extention, yes that's a html page if (!ext) { return true; } - // if this is htm or html, yes that's a html page - if (/^htm/.test(ext)) { - return true; + if (/^(gif|jpg|jpeg|tiff|png|pdf|css|ico|map|js)/.test(ext)) { + return false; } - - // if not we assume this is not as a html page - // this doesn't do any harm. But no SSR - return false; + // then return true + return true; } _getCachedPage(url, userId) { From 8b54289e23ee5ef06854b71503fd0b2dfdec197d Mon Sep 17 00:00:00 2001 From: TimoRuetten Date: Thu, 28 Jul 2016 16:00:17 +0200 Subject: [PATCH 3/4] A few fixes --- lib/router.js | 7 +++++++ server/plugins/ssr_data.js | 6 ++++++ server/route.js | 5 ++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/router.js b/lib/router.js index a66247e..5bec622 100644 --- a/lib/router.js +++ b/lib/router.js @@ -11,6 +11,9 @@ SharedRouter = class { this.env = {}; this.env.trailingSlash = new Meteor.EnvironmentVariable(); + + // Mongo Transforms + this.mongoTransforms = {}; } route(pathDef, options, group) { @@ -164,4 +167,8 @@ SharedRouter = class { withTrailingSlash(fn) { return this.env.trailingSlash.withValue(true, fn); } + + setMongoTransform(collection, transform) { + this.mongoTransforms[collection] = transform; + } }; diff --git a/server/plugins/ssr_data.js b/server/plugins/ssr_data.js index aa707b0..18d8bfa 100644 --- a/server/plugins/ssr_data.js +++ b/server/plugins/ssr_data.js @@ -26,9 +26,15 @@ Mongo.Collection.prototype.find = function(selector, options) { selector = selector || {}; const ssrContext = FlowRouter.ssrContext.get(); if (ssrContext && !FlowRouter.inSubscription.get()) { + console.log('A find for ' + this._name); const collName = this._name; const collection = ssrContext.getCollection(collName); const cursor = collection.find(selector, options); + + if (FlowRouter.mongoTransforms[colName]) { + cursor._transform = FlowRouter.mongoTransforms[collName]; + } + return cursor; } diff --git a/server/route.js b/server/route.js index 4ad84b8..02e8607 100644 --- a/server/route.js +++ b/server/route.js @@ -74,7 +74,7 @@ Route = class extends SharedRoute { } if (self.options.action) { - self.options.action(routeContext.params, routeContext.queryParams, req); + self.options.action(routeContext.params, routeContext.queryParams, req, res); } } catch (ex) { logger.error(`Error when doing SSR. path:${req.url}: ${ex.message}`); @@ -153,11 +153,10 @@ Route = class extends SharedRoute { _isHtmlPage(url) { const pathname = Url.parse(url).pathname; const ext = pathname.split('.').slice(1).join('.'); - // if there is no extention, yes that's a html page + // if there is no extention, yes that's a html page if (!ext) { return true; } - if (/^(gif|jpg|jpeg|tiff|png|pdf|css|ico|map|js)/.test(ext)) { return false; } From bc25d6b960e3596b34412eb5adb9f56de72980ad Mon Sep 17 00:00:00 2001 From: TimoRuetten Date: Thu, 28 Jul 2016 16:08:23 +0200 Subject: [PATCH 4/4] Added mongo transforms --- server/plugins/ssr_data.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/plugins/ssr_data.js b/server/plugins/ssr_data.js index 18d8bfa..d5315f0 100644 --- a/server/plugins/ssr_data.js +++ b/server/plugins/ssr_data.js @@ -26,12 +26,11 @@ Mongo.Collection.prototype.find = function(selector, options) { selector = selector || {}; const ssrContext = FlowRouter.ssrContext.get(); if (ssrContext && !FlowRouter.inSubscription.get()) { - console.log('A find for ' + this._name); const collName = this._name; const collection = ssrContext.getCollection(collName); const cursor = collection.find(selector, options); - if (FlowRouter.mongoTransforms[colName]) { + if (FlowRouter.mongoTransforms[collName]) { cursor._transform = FlowRouter.mongoTransforms[collName]; }