将文件动态插入到meteor 公共文件夹中而不隐藏它 [英] Dynamically insert files into meteor public folder without hiding it
问题描述
我有一个生成图像的流星应用程序.它们生成后,我想为它们服务.但是每次我写入公共文件夹时,我的流星服务器都会重新启动.我搜索了一个解决方案并找到了几种解决方法:
I have a meteor application that generates images. After they are generated, I want to serve them. But each time I write to the public folder, my meteor server restarts. I searched for a solution and found several workarounds:
在项目文件夹外提供文件 - 目前我不知道如何实现这一点,我是否必须编写某种集成到meteor中的中间件?
Serve files outside of the project folder - At the moment I don't know how to achieve this, would I have to write some kind of middleware that integrates into meteor?
在 public/
中的文件夹中添加一个波浪号 ~ - 这似乎让meteor 完全忽略该文件夹,当我尝试访问文件夹中的文件时,我被重定向到我的根页面.
Add a tilde ~ to the folder in public/
- which seems to make meteor ignore the folder altogether, when trying to access files in the folder I get redirected to my root page.
在生产模式下运行meteor.对我来说似乎是一个肮脏的解决方法.现在,meteor run --production
仍然会重新启动我的服务器,所以我必须捆绑我的应用程序,每次都重新安装光纤,设置我的环境变量,然后运行应用程序.每次我改变一些东西.
Run meteor in production mode. Seems like a dirty workaround for me. Right now, meteor run --production
still restarts my server so I have to bundle my app, reinstall fibers every time, set my environment variables and then run the app. Every time I change something.
还有其他解决方案吗?
推荐答案
接受的答案对我不起作用,但从 0.6.6.3 版本开始,您可以执行以下操作:
The accepted answer did not work for me, but as of version 0.6.6.3 you can do the following:
var fs = Npm.require('fs');
WebApp.connectHandlers.use(function(req, res, next) {
var re = /^/url_path/(.*)$/.exec(req.url);
if (re !== null) { // Only handle URLs that start with /url_path/*
var filePath = process.env.PWD + '/.server_path/' + re[1];
var data = fs.readFileSync(filePath, data);
res.writeHead(200, {
'Content-Type': 'image'
});
res.write(data);
res.end();
} else { // Other urls will have default behaviors
next();
}
});
注意事项
process.env.PWD
会给你项目根目录如果您打算将文件放入项目中
Notes
process.env.PWD
will give you the project rootif you plan to put files inside your project
- 不要使用
public
或private
流星文件夹 - 使用点文件夹(例如隐藏文件夹,例如:
.uploads
)
- don't use the
public
orprivate
meteor folders - use dot folders (eg. hidden folders ex:
.uploads
)
不遵守这两个将导致本地流星在每次上传时重新启动,除非您使用以下命令运行流星应用程序:
meteor run --production
Not respecting these two will cause local meteor to restart on every upload, unless you run your meteor app with:
meteor run --production
这篇关于将文件动态插入到meteor 公共文件夹中而不隐藏它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 不要使用