【问题标题】:Serving an "index.html" file in public/ when using MeteorJS and Iron Router?使用 MeteorJS 和 Iron Router 时在 public/ 中提供“index.html”文件?
【发布时间】:2014-07-15 07:31:57
【问题描述】:

我想从 MeteorJS 的公共文件夹中提供一个静态 HTML 文件(就像 Rails 和 Express 一样)。我这样做的原因是我有一个模板用于我的 web 应用程序的动态“管理”部分,另一个用于应用程序的销售“前端”部分。

我不希望按照this answer 的建议将此文件包装在 Meteor 模板中,因为它会自动引入动态页面使用的缩小 CSS 等。

有没有一种方法可以设置公用文件夹(及其所有子文件夹),以便它为 index.html 提供服务?这样http://app.com/会加载public/index.html?

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    您可以使用 private folder 代替,然后使用 Assets.getText 加载文件的内容,然后使用来自 iron-router 的服务器端路由器提供它。

    所以在我的脑海中,代码看起来像这样:

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

    【讨论】:

    • this.response.end(contents); 结束连接。
    • 嗨 Rahul,这很好用,但不适用于服务器生成的文件。例如,在 /private 文件夹中,有 test1.html 和 test2.html。当我部署到 Digital Ocean 服务器时,test1.html 和 test2.html 运行良好!但是,当我将 test3.html 生成到与 test1.html 和 test2.html 相同的文件夹中时,它只是显示“服务器错误”。如何使 test3.html 工作?谢谢!
    • 很难在没有看到您的代码的情况下提供帮助。请提出一个单独的问题。
    【解决方案2】:

    这是我输入的bootstrap.js

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-27
      • 2016-10-31
      • 2017-06-17
      • 2016-06-20
      • 2021-07-05
      • 2016-02-27
      • 1970-01-01
      相关资源
      最近更新 更多