提供“index.html"使用 MeteorJS 和 Iron Router 时公共文件/文件? [英] Serving an "index.html" file in public/ when using MeteorJS and Iron Router?
问题描述
我想从 MeteorJS 的公共文件夹中提供一个静态 HTML 文件(Rails 和 Express 是可能的).我这样做的原因是我有一个模板用于我的 web 应用程序的动态管理"部分,另一个用于应用程序的销售前端"部分.
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.
我不希望按照 this answer 因为它会自动引入动态页面使用的缩小的 CSS 等.
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
加载文件的内容,然后通过 Iron-router 的服务器端路由器为其提供服务.
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 时公共文件/文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!