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

前端 未结 2 532
情话喂你
情话喂你 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);
          }
        });
      });
    }
    

提交回复
热议问题