如何让 Meteor 上的服务器可以访问文本文件

问题描述:

我很惊讶我不能在这里用谷歌搜索我的答案......似乎没有其他人遇到这个问题.

I'm surprised I can't google my answer here... it seems no one else is having the issue.

当您运行meteor 服务时,js、html 等被打包在.meteor/local/build 文件夹中,但它似乎排除了不是js 或html 的内容.我有一个名为magicsets"的文件夹和一个名为magicimgs"的文件夹,它们都不在/local/build 文件夹中.这显然是为什么当我尝试使用 fs 读取文件时,它无法找到文件magicssets/M14.json"

When you run the meteor service the js, html, etc. is packaged in the .meteor/local/build folder, but it appears to exclude stuff that isn't js or html. I have a folder called "magicsets" and one called "magicimgs" and neither are in the /local/build folder. This is obviously why, when i attempt to use fs to readfile, it fails to find the file "magicsets/M14.json"

我尝试将 magicsets 文件夹放入名为private"的文件夹中,但没有任何效果.

I tried putting the magicsets folder into a folder named "private", but that didn't accomplish anything.

如何通过 FS 使我的服务器可以在本地访问文件,以及如何通过原始 URL 使我的服务器可以公开访问文件?

How do I make files accessible locally to my server via FS and how do I make files accessible publically to my server via raw urls?

我确定我遗漏了一些非常简单的东西,因为关于 SO 有很多更复杂的问题和答案,但没有答案.谢谢.

I'm sure I'm missing something very simple, because there are lots of more complicated questions and answers on SO, yet there is no answer for this. Thanks.

昨天发布的 Meteor 0.6.5 有一个新功能可以帮助加载.

Meteor 0.6.5 which was released yesterday has a new feature which helps loads with this.

创建一个名为 /private 的目录,您可以使用新的 Assets.getTextAssets.getBinary 函数.

Make a directory called /private which you can access with the new Assets.getText or Assets.getBinary functions.

/private 目录中的内容将被打包到 /program/server/assets 中名为 assets 的目录中将无法访问网络 &您也无需担心使用 fs.你可以使用 Assets.getText 代替

The stuff in the /private directory will then be bundled up into a directory called assets in /program/server/assets and it will not be accessible to the web & you wouldn't need to worry about using fs either. You could just use Assets.getText instead

要制作可公开访问的文件,请将其放在 /public 中.因此,如果您在 /public/a.jpg 上有 a.jpg,则可以通过 http://yourdomain.com/a.jpg

To make a publicly accessible file put it in /public. So if you had a.jpg at /public/a.jpg it would be accessible at http://yourdomain.com/a.jpg