Meteor is great at building sophisticated Single Page Applications. But if the application also has traditional (informational) pages - fast load, seo friendly, multipage sections - it is surprisingly difficult to do.
- managing templates - just as they are managed on the client
- serving static files - from a folder (using ideas from williamledoux:static-server)
- preventing restart on every save in development - but autoloading on refresh.
- rendering along with head sections. (using SSR - thanks to meteorhacks:ssr )
- getting userId on server side - using a token-cookie linked to userId. To be used for customization only - not for any sensitive information or workflow.
meteor add viloma:server-pages
These can be defined using Iron:Router - note that The "where: server" - is Important!
if(Meteor.isServer){
Router.route('/event/:evtid', function() {
var evt = Events.findOne({_id: this.params.evtid});
ServerPages.render("eventpage", {e: evt}, this.response);
}, {where:'server'});
}
You place need to place static files and templates under .spages folder under project root folder -
projectroot/.spages/public - for static files projectroot/.spages/templates - for templates
- All the files under /.spages/public - are served from url /files/ .
- All templates under /.spages/templates - are loaded for rendering
- changes to files in the .spages folder - do not cause meteor to restart - making for a much better development workflow.
- templates changes are still picked up on page refresh.
- Static files and templates are packaged and included in the build.
<template name='eventpage'>
<img src='/files/images/logo.jpg' />
.....
</template>
<template name='head'>
<script ... > <link ... > This is common head tag for all pages
</template>
<template name='head-eventpage'>
<meta ... > head elements for eventpage template go here
</template>
- sometimes when showing static pages - you need minor customizations for a user
- you can get the indicative users using the api ServerPages.getIndicativeUser(this.request)
ServerPages.getIndicativeUser(this.request)
ServerPages.getIndicativeUserId(this.request)
**This should NEVER be used for any sensitive information or for transactions **. Those should happen over DDP in meteor SPA pages.
lastly if you dont want to use .spages folder - but just want to compile a template - put it in private folder
ServerPages.compileTemplate(Assets.getText('filename.txt'))
- meteorhacks:ssr - rendering blaze and jade templates on server side.
- staticserver - rendering static files from server [@thomasfuchs].
MIT