Serving an “index.html” file in public/ when using MeteorJS and Iron Router?

前端 未结 2 529
情话喂你
情话喂你 2021-01-05 16:54

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

相关标签:
2条回答
  • 2021-01-05 17:38

    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);
          }
        });
      });
    }
    
    0 讨论(0)
  • 2021-01-05 17:39

    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);
    });
    
    0 讨论(0)
提交回复
热议问题