服务"index.html"使用MeteorJS和Iron Router时在public/中保存文件? [英] Serving an "index.html" file in public/ when using MeteorJS and Iron Router?

查看:78
本文介绍了服务"index.html"使用MeteorJS和Iron Router时在public/中保存文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从MeteorJS的公用文件夹中提供一个静态HTML文件(Rails和Express可以这样做).之所以这样做,是因为我有一个模板用于Web应用程序的动态管理员"部分,而另一个模板则用于应用程序的sales-y前端"部分.

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.

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

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?

推荐答案

您可以使用 private文件夹,然后使用 Assets.getText 加载文件的内容,然后将其与铁路由器的服务器端路由器.

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

这篇关于服务"index.html"使用MeteorJS和Iron Router时在public/中保存文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆