2

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

denis631
  • 1,765
  • 3
  • 17
  • 38

1 Answers1

3

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.

Vadim Eisenberg
  • 3,337
  • 1
  • 18
  • 14