How to set StaticFileServer() using Kitura?

417 views Asked by At

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

1

There are 1 answers

4
Vadim Eisenberg On BEST ANSWER

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.