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..d5315f0 100644 --- a/server/plugins/ssr_data.js +++ b/server/plugins/ssr_data.js @@ -29,6 +29,11 @@ Mongo.Collection.prototype.find = function(selector, options) { const collName = this._name; const collection = ssrContext.getCollection(collName); const cursor = collection.find(selector, options); + + if (FlowRouter.mongoTransforms[collName]) { + cursor._transform = FlowRouter.mongoTransforms[collName]; + } + return cursor; } diff --git a/server/route.js b/server/route.js index 28d68a5..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); + self.options.action(routeContext.params, routeContext.queryParams, req, res); } } catch (ex) { logger.error(`Error when doing SSR. path:${req.url}: ${ex.message}`); @@ -153,20 +153,15 @@ 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 (!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) {