Meteor.js usage
July 8, 2025 ยท View on GitHub
Setup "spiderable" pre-rendering middleware for Meteor.js-based application
Examples:
Installation
Install Atmosphere webapp and ostrio:spiderable-middleware packages
meteor add webapp
meteor add ostrio:spiderable-middleware
This is SERVER only package. For Meteor.js please make sure library imported and executed only on SERVER.
Usage example
Import necessary packages and initiate new Spiderable instance
// Make sure this code executed only on SERVER
// Use `if (Meteor.isServer) {/*...*/}` blocks
// or place this code under `/server/` directory
import { WebApp } from 'meteor/webapp';
import Spiderable from 'meteor/ostrio:spiderable-middleware';
const spiderable = new Spiderable({
auth: 'test:test'
});
// meteor@>=3 use the next line for modern version of Meteor
WebApp.connectHandlers.use(spiderable.handle);
// meteor@<3 use the next line for meteor@2.x and meteor@1.x releases
WebApp.connectHandlers.use(spiderable);
Detect request from Pre-rendering engine in Meteor.js
Pre-rendering engine will set window.IS_PRERENDERING global variable to true. As in Meteor/Blaze everything should be reactive, let's bound it with ReactiveVar:
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
const isPrerendering = new ReactiveVar(window.IS_PRERENDERING || false);
Object.defineProperty(window, 'IS_PRERENDERING', {
set(val) {
isPrerendering.set(val);
},
get() {
return isPrerendering.get();
}
});
// Make globally available Blaze helper,
// Feel free to omit this line in case when Blaze no used
// or going to handle logic in JavaScript part
Template.registerHelper('IS_PRERENDERING', () => isPrerendering.get());
Note: window.IS_PRERENDERING can be undefined on initial page load, and may change during runtime.
Types
Import types right from Atmosphere package
import Spiderable from 'meteor/ostrio:spiderable-middleware';
import type { SpiderableOptions, NextFunction } from 'meteor/ostrio:spiderable-middleware';
const options: SpiderableOptions = {
rootURL: 'http://example.com',
auth: 'test:test',
debug: false,
/* ..and other options.. */
};
expectType<SpiderableOptions>(options);
const spiderable = new Spiderable(options);
expectType<Spiderable>(spiderable);
const next: NextFunction = (_err?: unknown): void => {};
expectType<void>(spiderable.handle(req, res, next));
Further reading
Running Tests
- Clone this package
- In Terminal (Console) go to directory where package was cloned
- Then run:
Meteor/Tinytest
ROOT_URL=http://127.0.0.1:3003/ meteor test-packages ./ --port 3003
# Run same tests with extra-logging
DEBUG=true ROOT_URL=http://127.0.0.1:3003/ meteor test-packages ./ --port 3003
# PORT is required, and can be changed to any local open port
Get $50 off pre-rendering service
For Meteor-folks who read documentation to the very end โ get $50 off the second purchase at ostr.io, use this link to sign up. Valid only for new users.