Skip to content

Commit

Permalink
Prerender.io Integration - Feature #1249 (#1643)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer Norman authored and brent-hoover committed Dec 20, 2016
1 parent 68d0ba5 commit 0816308
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<head>
<meta name="fragment" content="!">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<noscript><div style="padding: 40px; font-size: 200%; text-align: center;">This site requires JavaScript. Please enable it in your browser settings.</div></noscript>
</head>
1 change: 1 addition & 0 deletions imports/plugins/core/layout/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import "./templates/layout/loading/loading.html";
import "./templates/layout/notFound/notFound.html";
import "./templates/layout/notFound/notFound.js";
import "./templates/layout/notice/unauthorized.html";
import "./templates/layout/notice/unauthorized.js";
import "./templates/layout/layout.html";

import "./templates/theme/theme.html";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { Template } from "meteor/templating";

Template.notFound.onCreated(function () {
document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeend", "<meta name='prerender-status-code' content='404'>");
// todo report not found source
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Template } from "meteor/templating";

Template.unauthorized.onCreated(function () {
document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeend", "<meta name='prerender-status-code' content='403'>");
// todo report not found source
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Template.products.onCreated(function () {
canLoadMoreProducts: false
});

// We're not ready to serve prerendered page until products have loaded
window.prerenderReady = false;


// Update product subscription
this.autorun(() => {
const slug = Reaction.Router.getParam("slug");
Expand All @@ -71,7 +75,12 @@ Template.products.onCreated(function () {
this.state.set("slug", slug);

const queryParams = Object.assign({}, tags, Reaction.Router.current().queryParams);
this.subscribe("Products", scrollLimit, queryParams);
const productsSubscription = this.subscribe("Products", scrollLimit, queryParams);

// Once our products subscription is ready, we are ready to render
if (productsSubscription.ready()) {
window.prerenderReady = true;
}

// we are caching `currentTag` or if we are not inside tag route, we will
// use shop name as `base` name for `positions` object
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"paypal-rest-sdk": "^1.6.9",
"postcss": "^5.2.5",
"postcss-js": "^0.1.3",
"prerender-node": "^2.6.0",
"radium": "^0.18.1",
"react": "^15.3.2",
"react-addons-create-fragment": "^15.3.2",
Expand Down
2 changes: 2 additions & 0 deletions server/startup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Load from "./load-data";
import Packages from "./packages";
import Registry from "./registry";
import Init from "./init";
import Prerender from "./prerender";
import { initTemplates } from "/server/api/core/templates";


Expand All @@ -15,4 +16,5 @@ export default function () {
Packages();
Registry();
Init();
Prerender();
}
13 changes: 13 additions & 0 deletions server/startup/prerender.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import prerender from "prerender-node";
import { WebApp } from "meteor/webapp";
import { Logger } from "/server/api";

export default function () {
if (process.env.PRERENDER_TOKEN && process.env.PRERENDER_HOST) {
prerender.set("prerenderToken", process.env.PRERENDER_TOKEN);
prerender.set("host", process.env.PRERENDER_HOST);
prerender.set("protocol", "https");
WebApp.rawConnectHandlers.use(prerender);
Logger.info("Prerender Initialization finished.");
}
}

0 comments on commit 0816308

Please sign in to comment.