Subscribe to a custom publication


#1

I’ve followed this doc article https://guide.meteor.com/data-loading.html#loading-from-rest
to set up a simple custom publication (I modified the example code for a simple test without a need to setup a 3rd REST endpoint):

const POLL_INTERVAL = 5000;
var count = 0;

Meteor.publish('polled-publication', function() {
	this.added("simple_counter", 'id', {value: count});
	const poll = () => {
		count++;
		this.changed("simple_counter", 'id', {value: count});		
	};

	poll();
	this.ready();

	const interval = Meteor.setInterval(poll, POLL_INTERVAL);

	this.onStop(() => {
		Meteor.clearInterval(interval);
	});
});

For the client subscriber side I tried simple:rest which was also mentioned in the same article. I could see the publication data in JSON when requesting http://host:port/publications/polled-publication. I assume in this method, the publication must be polled by sending http requests and the responses must be parsed for example before inputting into templates.

Are there any meteor APIs/packages that support accessing custom publication data (DB less) in form of js objects and with reactivity? I saw the published collection data pushed to client when monitoring the websocket transmission after Meteor.subscribe() is called. There would be no need for client to poll on it. What are the options to pull these data in client code?


#2

Maybe take a look at the okgrow:rest2ddp package. It helps you create publications for REST API’s (which you can then consume client side reactively). Small caveat - this package is no longer actively maintained, but it is still getting bug fixes. Note from OK GROW!:

DISCLAIMER - Development of this package is currently on hiatus. We are currently not actively developing this package due to both resource constraints and uncertainty about how well supported it will be in the future. We are using this in our active projects, so we will continue to do bug fixes as we encounter them, but feature requests may go unanswered. PRs are still welcome.

(source: GH repo)


#3

Cool package. Seems like the only downside is no SEO at all (for pulled in blog posts for example), even with prerender and mdg:seo. Correct?