fdy is a simple, effortless file server with nifty features such as URL rewriting (see fdy.replace), file directory listing, and file manipulation (see fdy.handle)
do it
var fdy=;fdy;
Settings
Settings including cache
, index
, and directory
were removed as of 2.0.0. Directory now defaults to ./public
fdy.on(event, callback)
Handle events. Currently the only event is "request"
.
event
Stringcallback
Function(request, response)
fdy.header(type, header)
Set headers for specific file mimetypes (ex. text/plain
) or general types (ex. text/*
).
type
Stringheader
Object
fdy;
fdy.hide(path)
As of 0.0.1, only allows a single RegExp
As of 1.0.5, functions similarly to replace
As of 2.0.0 (current), only accepts specific path or file names
path
String
fdy.replace(regex, string)
Make changes to path before handling (i.e. /js/
→ /files/js/
).
regex
RegExp | Stringstring
String (Function would also work, as it is a regularreplace
)
fdy.redirect(regex, string)
Serve 302 to specified path (i.e. /blog/
→ http://external.blog/
).
regex
RegExp | Stringstring
String
fdy.forbidden(regex, files)
Serve 403 from specified path (if directory, also excludes files by default).
regex
RegExp | Stringfiles
Boolean (true
to allow direct file requests such as images)
fdy.handle(path, callback[, exists])
Manipulate select data before sending it. The first argument determines what requests a handle applies to based on url.
exists
(default false
) determines whether a file is expected to already exist (enabling the data
field in the callback). If false or undefined, the handle is called without loading the file.
path
Stringcallback
Function(request, response[, data], query)
Pages
Currently supports 403
, 404
and DIR
-- point to files to serve for respective pages. Grabs from ./public
since any external files (such as stylesheets) would have to be public as well.
app.js
fdy;fdy;fdy;fdy;
directory.html
The directory page uses a special jht format since its content is dynamic.
index of {path} File Size Modified {each files} {name} {size} {date} {/each}
Help, stuff broke!
There have been significant changes with each update and for the sake of moving forward backwards compatibility has not been a huge concern. You can use a previous version or just rename a few functions in your code (i.e. fdy.set
became fdy.page
). Your biggest burden is probably going to be updating your custom DIR
template if you have one, and for that I apologize.