swiftlocalhostfileserverkituraserver-side-swift

How to set StaticFileServer() using Kitura?


I want to see files in my localhost directory using Kitura. I've written:

router.all("/test/*", middleware: StaticFileServer())

but it didn't seem to work

I want to all files in my directory. Similar to directoryIndex


Solution

  • You can pass the path to a directory to serve to StaticFileServer, as path parameter, by default it is "public":

    router.all("/test/", middleware: StaticFileServer(path: "MyDirectoryWithStaticFiles"))

    Then you will be able to access the files in this directory, but not the directory itself. E.g., you will be able to perform GET /test/someFile.html, but not /test/. You will be able to GET /test/, if your directory will contain index.html.

    See https://github.com/IBM-Swift/Kitura-Sample for example of using StaticFileHandler.