Meteor 和 /private 目录

Meteor and the /private directory

我目前正在使用 Meteor 1.0.3 中的 /private 目录来存储 pdf 文档并将其提供给浏览器。

例如,我的文件夹结构如下:

/application-name
 /private
  /files
   /users
    /user-name
     /pdf-file1.pdf 

我有一个带有按钮点击事件的模板。在这种情况下,我对 Meteor 方法进行了几次调用,最后调用了服务器端 Iron Router go('render-pdf') 方法。在这些 Meteor 方法中,我使用 fs node.js 来:

(1) check if the /user-name directory exists, and if it doesn't I create it.

(2) create the pdf-file.pdf file

然后在服务器端Iron Routergo('render-pdf')路由,再次使用fsnode.js到:

(3) read the created pdf-file.pdf and

(4) finally render it to the browser

问题出在第(1)步,创建/user-name目录时,Meteor服务器重启。在步骤 (2) 中,Meteor 服务器再次重启。

But most importantly, the first time my code runs, and the directory does not exist (step (1)), I get an error.

然后我可以再次调用按钮事件,这次是在目录创建之后,并且 pdf 渲染正常。

错误看起来是这样的:

Error: ENOENT, no such file or directory '/Users/myname/meteor/meteor-application/private/files/users/user-name/pdf-file.pdf' at Object.fs.openSync (fs.js:438:18) at Object.fs.readFileSync (fs.js:289:15) at [object Object].Router.route.name (meteor-application/both/routes.js:225:17) at boundNext (packages/iron:middleware-stack/lib/middleware_stack.js:251:1) at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108:1) at packages/meteor/dynamics_nodejs.js:121:1 at [object Object].urlencodedParser (/Users/myname/.meteor/packages/iron_router/.1.0.7.15dqor4++os+web.browser+web.cordova/npm/node_modules/body-parser/lib/types/urlencoded.js:72:36) at packages/iron:router/lib/router.js:277:1 at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1) at [object Object].hookWithOptions (packages/iron:router/lib/router.js:276:1)

可能是当我到达尝试呈现文件的第 (4) 步时,它要么不存在,要么应用程序正在重新启动。下次我尝试时应用程序已经重新启动并且文件存在。

I was under the impression that the /private directory provides a place to handle files that do not affect the execution of the application? To me this means, at runtime I can add whatever I want without the application restarting.

小历史

起初我使用 /server 目录和 ./folder-name 子目录。这在我添加文件夹和文件时起作用,应用程序没有重新启动。缺点是当我使用很棒的 Meteor-up 包 (mup) 部署 Meteor 时,部署包会忽略这些文件,除非我在其中某处添加了 *.js 文件。此外,如果我在我的 EC2 实例上创建了 'hidden' 文件夹结构,部署将删除该目录。

所以使用 /private 文件夹解决了这个问题,或者我是这么认为的。文件夹结构和 'assets' 已部署。但是这种方法的缺点是当我向它添加 'assets' 时,它似乎重新启动了 -- even though I though this wasn't something that was suppose to happen.

问题

如何在不重启Meteor应用程序的情况下,在/private目录下添加'assets'(以目录和文件的形式)?如果无法完成,我如何在不重新启动应用程序的情况下仅在服务器端添加 'assets'

请注意

当我部署到生产环境时,我希望保留一些文件夹结构,例如:

/private/files/users

应该说那里,而

/user-name 

目录可以是动态的。我只提到这一点,因为我读过如果你做 /.directory-name,Meteor 会忽略该文件夹及其内容。但这也包括部署。

我真正需要的

包含在部署包中的仅服务器端文件夹,当我在运行时向其添加 'stuff' 时,不会重新启动我的应用程序...

Either a way to include /.hidden-folder in my mup deployment bundle or have the /private folder not restart every time I add stuff to it at runtime.

为了避免:

(1)overwriting/removing我每次部署的目录结构,

(2) 每次创建目录或文件时重新启动 Meteor 应用程序。

我决定在我的例子中使用Meteor项目外部的目录结构而不是[=36=是有意义的]里面 和以前一样。

类似 Dropbox/users/user-name 之类的东西,或者其他任何东西。

我现在认为 /private 和 /public 文件夹更适合静态内容。

我并没有真正存储那么多文件,其中一些无论如何只是临时的,所以这个方法会阻止我直到我移动到像[=这样的东西11=].

请注意:

(1) 您需要授予您的 Meteor 用户访问项目外部目录的权限。

(2) 考虑到这将占用 space 您的 OS Instance HD。

(3) 您需要使用 Node.js 进行文件系统调用。这些调用未封装在 Meteor Fibers 中,因此您在 async/sync 编程方面只能靠自己。