Serving an “index.html” file in public/ when using

2019-02-14 06:16发布

问题:

I want to serve a static HTML file from MeteorJS's public folder (as is possible with Rails and Express). The reason I'm doing this is because I have one template for the dynamic "admin" part of my webapp and another for the sales-y "frontend" part of the app.

I don't want this file to be wrapped in a Meteor template as suggested in this answer as it will automatically bring in the minified CSS, etc... that the dynamic pages use.

Is there a way I can setup the public folder (and all its subfolders) so that it serves index.html? This way http://app.com/ will load public/index.html?

回答1:

You could use the private folder instead and then use Assets.getText to load the contents of the file, then serve it with a server-side router from iron-router.

So off the top of my head the code would look something like this:

if (Meteor.isServer) {
  Router.map(function() {
    this.route('serverRoute', {
      path: '/',
      where: 'server',
      action: function() {
        var contents = Assets.getText('index.html');
        this.response.end(contents);
      }
    });
  });
}


回答2:

this is what I put in bootstrap.js

Router.route('/', {
  where: 'server'
}).get(function() {
  var contents;
  contents = Assets.getText('index.html');
  return this.response.end(contents);
});