Serving static content
While Fiction is mainly focused on BashX, it has support for many other content types and routes
Static content and HTML
Section titled “Static content and HTML”You can serve files content using fiction.serveFile function:
fiction.serveFile "<file>" "<routeAlias?>" "<content type?>"This function creates a route which points to function that returns file’s contents with it’s type
You can serve static HTML the same way by using text/html as content type
fiction.serveFile "index.html" "/" "text/html"fiction.server "0.0.0.0:8080"This code would show index.html as HTML (text/html) on root route (/)
Directories
Section titled “Directories”Fiction supports directory file listing using fiction.serveDir
Let’s say we have directory test:
Directorytest/
- test.txt
- test.png
- index.sh
fiction.serveDir "./test" "/files" false trueThis would create following routes:
/files: file tree of ./test/files/test.txt: contents of test.txt/files/test.png: image/files/index.sh: contents of index.sh