我想使用 Kitura 查看 localhost 目录中的文件。 我写过:
router.all("/test/*", middleware: StaticFileServer())
但是好像没用
我想要目录中的所有文件。类似于目录索引
最佳答案
您可以将要服务的目录路径作为path
参数传递给StaticFileServer
,默认情况下为“public”
:
router.all("/test/", 中间件: StaticFileServer(path: "MyDirectoryWithStaticFiles"))
然后您将能够访问该目录中的文件,但不能访问该目录本身。例如,您将能够执行 GET /test/someFile.html
,但不能执行 /test/
。如果您的目录包含 index.html
,您将能够 GET /test/
。
参见https://github.com/IBM-Swift/Kitura-Sample例如使用StaticFileHandler
。
关于swift - 如何使用 Kitura 设置 StaticFileServer()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46073993/