流星+ React + ReactRouter文件上传

Isu*_*uru 5 meteor reactjs react-router meteor-react

我目前正在使用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
Run Code Online (Sandbox Code Playgroud)

我已经设置了CollectionFS,将zip文件存储到文件系统中,并使用meteorhacks:npm和几个npm软件包,可以将文件解压缩到一个已知位置。

ZippedFolder
    |-- css
    |    |-- bootstrap.css
    |    |-- bootstrap.min.css 
    |    +-- style.css
    |-- js
    |    |-- bootstrap.js
    |    |-- bootstrap.min.js
    |    +-- script.js 
    +- index.html
Run Code Online (Sandbox Code Playgroud)

在React组件上,我正在使用以下代码片段上传压缩的HTML内容。

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
  }));
})); 
Run Code Online (Sandbox Code Playgroud)

上传和解压缩有效。但是,CollectionFS不提供HTML或解压缩路径中的其他内容。

 http://meteorhost/cfs/files/html_content/file_id/index.html
Run Code Online (Sandbox Code Playgroud)

我还尝试将html内容解压缩到流星文件夹结构的公用文件夹中。但是,流星文档指出公用文件夹用于静态资产。因为它维护公用文件夹中资产的索引。因此,需要重新启动服务器才能更新索引。

还有其他可以放置HTML内容的位置吗?

更新我通过设置nginx虚拟目录并将文件上传到该位置来解决此问题,以便nginx将提供HTML内容。