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

≯℡__Kan透↙ 提交于 2019-12-30 06:41:26

问题


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);
});


来源:https://stackoverflow.com/questions/23871590/serving-an-index-html-file-in-public-when-using-meteorjs-and-iron-router

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!