Serves pages that contain directory listings for a given path. forked from expressjs/serve-directory
yarn add serve-directoryimport serveDirectory from 'serve-directory'
const directory = serveDirectory('wwwroot', options)see example.js
Returns middleware that serves an index of the directory in the given path.
The path is based off the req.url value, so a req.url of '/some/dir
with a path of 'public' will look at 'public/some/dir'. If you are using
something like express, you can change the URL "base" with app.use (see
the express example).
serveDirectory accepts these properties in the options object.
{
imports: {},
hidden: false,
relative: true,
process: [
{
accept: 'text/html',
render: 'lib/directory.jst'
},
{
accept: 'text/plain',
render: ({fileNames}) => fileNames.join(EOL) + EOL,
},
{
accept: 'application/json',
render: ({fileNames}) => JSON.stringify(fileNames),
},
]
}An object to import into the template as free variables., see lodash.template
by default some useful functions will import automatically
see utils/index.js
options.hidden(Boolean)
Show hidden files(file/folder start with .) , defaults to false.
Use relative url , default true.
Array list how data should be handled
Array or String split with ,
space will be trim
by default we use a compiled lodash.template function to render data
see lodash.template
-
Stringa path to a template file a template string
-
Functiona custom render function
-
falsyvalueremove default render function
data pass to the render function
-
path
Stringphysical path
-
pathname
Stringdecoded request pathname
-
url
URLrequest URL object
-
method
Stringrequest method
-
responseType
Stringresponse mine-type / content-type
-
directory
fs.Statsdirectory stats with additional info
pathpathnameurl -
files
Array<fs.Stats>directory files stats with additional info
nameexttypeurl -
fileNames
Array<String>directory files but
nameonly
MIT © fisker Cheung