我目前正在使用Meteor,ReactJS和React Router(用于路由)开发应用程序 . 我有一个要求,即用户应该能够上传压缩的网站,而Meteor应用程序需要将此网站显示为其中一个页面的一部分 .
典型的zip文件将包含与下面类似的模式,
ZippedFolder
|-- css
| |-- bootstrap.css
| |-- bootstrap.min.css
| +-- style.css
|-- js
| |-- bootstrap.js
| |-- bootstrap.min.js
| +-- script.js
+- index.html
我已经设置了CollectionFS来将zip文件存储到文件系统中并使用meteorhacks:npm和几个npm包,我能够将该文件解压缩到已知位置 .
HTMLContent = new FS.Collection("html_content", {
stores: [new FS.Store.FileSystem("html_content"]
});
HTMLContent.on('stored', Meteor.bindEnvironment(function (fileObj) {
let unzip = Meteor.npmRequire('unzip'),
fs = Meteor.npmRequire('fs'),
path = fs.realpathSync(process.cwd() + '/../../../cfs/files/html_content/'),
file = fs.realpathSync(path + '/' + fileObj.copies.html_content.key),
output = path + '/' + fileObj._id;
// TODO: Not the best ways to pick the paths. For demo only.
if (!fs.existsSync(output)) {
fs.mkdirSync(output);
}
fs.createReadStream(file).pipe(unzip.Extract({
path: output
}));
}));
在React组件上我使用以下代码片段上传压缩的HTML内容 .
handleZIPUpload(event) {
FS.Utility.eachFile(event, function(file) {
HTMLContent.insert(file, function(err, fileObj) {
if (err) {
console.log(err);
} else {
console.log(fileObj);
}
});
});
},
render(){
return (
<input id="html_content" type="file" onChange={this.handleZIPUpload}/>
)
}
上传和解压缩工作 . 但是,CollectionFS不提供解压缩路径中的HTML或其他内容 .
http://meteorhost/cfs/files/html_content/file_id/index.html
我也尝试将html内容解压缩到meteor文件夹结构的公共文件夹 . 但是,meteor文档指出公用文件夹适用于静态资产 . 因为它维护公用文件夹中资产的索引 . 因此,需要重新启动服务器才能更新索引 .
是否还有其他位置可以放置可以按原样提供的HTML内容?
更新我通过设置nginx虚拟目录并将文件上传到该位置来排序此问题,以便nginx将提供HTML内容 .