tourist/static
src/tourist/static.tur
static file serving with path-traversal guard.
Since: v0.1.0
defn
serve-static!
(serve-static! [url-prefix : cstr fs-root : cstr] :)
declare a static-file serving route.
Parameters
| url-prefix | URL path prefix to strip, e.g. "/assets" | |
| fs-root | filesystem directory to serve from, e.g. "./public" |
Returns
:int -- static Route handle; consumed by tourist
Example
(serve-static! "/assets" "./public")
Since: v0.1.0
defn
static-item?
(static-item? [item : int] :)
true if an item handle is a static-file route.
Parameters
| item | :int item handle from serve-static! or any other DSL constructor |
Returns
:bool
Since: v0.1.0
defn
static-route-fs-root
(static-route-fs-root [route : int] :)
filesystem root directory of a static route.
Parameters
| route | :int static route handle from serve-static! |
Returns
:cstr -- absolute or relative path to the served directory
Since: v0.1.0
defn
static-serve
(static-serve [fs-root : cstr rel-raw : int] :)
serve a file from fs-root; returns 0 on any miss.
Parameters
| fs-root | :cstr filesystem root directory | |
| rel-raw | :int relative path as char* cast to int64_t (from wildcard | |
| capture); 0 is treated as a miss |
Returns
:int -- Response handle (200 + body) on success, 0 on miss
Since: v0.1.0
Internal definitions
__static-pat-join-- build "<prefix>/*" by concatenating two cstrs.__static-route-alloc-- allocate a __tourist_static_route struct.