简体   繁体   English

如何使用 serve-static 提供多个文件?

[英]How to serve multiple files with serve-static?

I am using serve-static with node to serve basic static html files.我正在使用带有节点的 serve-static 来提供基本的静态 html 文件。

There is a folder containing all of the individual pages you can visit:有一个文件夹包含您可以访问的所有单个页面:

pages
  -A.html
  -B.html
  -C.html

To visit these you simply attach the path to each file in the directory, something like: localhost:3000/pages/a.html .要访问这些,您只需将路径附加到目录中的每个文件,例如: localhost:3000/pages/a.html

Outside of this directory, there is a special.html .在这个目录之外,有一个special.html I would like this file to be served to the client alongside any of the pages you might be viewing.我希望将此文件与您可能正在查看的任何页面一起提供给客户端。

So for example if you are at localhost:3000/pages/a.html , the client will be served both a.html and special.html .例如,如果您在localhost:3000/pages/a.html ,客户端将同时获得a.htmlspecial.html Is this possible?这可能吗? Maybe special could be a wrapper to the pages?也许特别的可能是页面的包装器?

Sure, one way you can solve this is to add an iframe to a, b, and c pages with special.html content.当然,您可以解决此问题的一种方法是将iframe添加到具有 special.html 内容的 a、b 和 c 页面。 So adding the below line in a, b, and c should do the trick (depending on the path to special.html)因此,在 a、b 和 c 中添加以下行应该可以解决问题(取决于 special.html 的路径)

<iframe id="myIframe" src="./special.html"></iframe>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM