Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added request object to FlowRouter action parameters #665

Open
wants to merge 5 commits into
base: ssr
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ SharedRouter = class {

this.env = {};
this.env.trailingSlash = new Meteor.EnvironmentVariable();

// Mongo Transforms
this.mongoTransforms = {};
}

route(pathDef, options, group) {
Expand Down Expand Up @@ -164,4 +167,8 @@ SharedRouter = class {
withTrailingSlash(fn) {
return this.env.trailingSlash.withValue(true, fn);
}

setMongoTransform(collection, transform) {
this.mongoTransforms[collection] = transform;
}
};
5 changes: 5 additions & 0 deletions server/plugins/ssr_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
15 changes: 5 additions & 10 deletions server/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -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) {
Expand Down