reblocks-file-server

2023-06-18

A Reblocks extension allowing to create routes for serving static files from disk.

Upstream URL

github.com/40ants/reblocks-file-server

Author

Alexander Artemenko <svetlyak.40wt@gmail.com>

License

Unlicense
README

reblocks-file-server - A Reblocks extension allowing to create routes for serving static files from disk.

REBLOCKS-FILE-SERVER ASDF System Details

Installation

You can install this library from Quicklisp, but you want to receive updates quickly, then install it from Ultralisp.org:

(ql-dist:install-dist "http://dist.ultralisp.org/"
                      :prompt nil)
(ql:quickload :reblocks-file-server)

Usage

Here is a few examples on how this library can be used. These lines can be added into the code which starts your Reblocks web application.

This is how to serve all *.txt files from the /var/www folder:

(reblocks-file-server:make-route :uri "/static/"
                                 :root "/var/www/"
                                 :dir-listing nil
                                 :filter ".*.txt")

You also can provide a DIR-LISTING argument to repond on /static/ route with a rendered directory listing:

(reblocks-file-server:make-route :uri "/static/"
                                 :root "/var/www/"
                                 :dir-listing t
                                 :filter ".*.txt")

In case if you want to serve all files except *.txt, you can negate filter expression by giving NIL in FILTER-TYPE argument:

(reblocks-file-server:make-route :uri "/static/"
                                 :root "/var/www/"
                                 :dir-listing t
                                 :filter ".*.txt"
                                 :filter-type nil)

API

REBLOCKS-FILE-SERVER/CORE

package reblocks-file-server/core

Classes

STATIC-FILES-ROUTE

class reblocks-file-server/core:static-files-route (route)

Readers

reader reblocks-file-server/core:get-dir-listing (static-files-route) (:dir-listing = t)

When nil, directory contents is not shown.

reader reblocks-file-server/core:get-filter (static-files-route) (:filter)

A regular expression.

reader reblocks-file-server/core:get-filter-type (static-files-route) (:filter-type = t)

T means show files that match the filter regexp. NIL means hide files that match the filter regexp

reader reblocks-file-server/core:get-root (static-files-route) (:root)

reader reblocks-file-server/core:get-uri (static-files-route) (:uri)

Generics

generic-function reblocks-file-server/core:render-404 route uri

Returns a string with HTML for a case when `uri' wasn't found on the disk.

generic-function reblocks-file-server/core:render-directory route uri children

Renders a list of files in a directory

generic-function reblocks-file-server/core:render-styles route

This method should use reblocks/html:with-html and output a :style element.

generic-function reblocks-file-server/core:serve-directory route uri full-path

Returns a Lack response with a rendered directory listing.

generic-function reblocks-file-server/core:serve-file route full-path

Returns content of the file.

Functions

function reblocks-file-server/core:list-directory full-path filter filter-type

Returns a list of files in the directory. All items of the list are relative.

function reblocks-file-server/core:make-route &key (route-class 'static-files-route) (uri "/") (root "./") (dir-listing t) (filter ".*") (filter-type t)

[generated by 40ANTS-DOC]

Dependencies (12)

  • 40ants-asdf-system
  • ci
  • cl-fad
  • cl-ppcre
  • cl-routes
  • doc
  • docs-builder
  • named-readtables
  • pythonic-string-reader
  • reblocks
  • rove
  • trivial-mimes

Dependents (1)

  • GitHub
  • Quicklisp