Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/strugee/node-serve-random
Express middleware that responds with random files
https://github.com/strugee/node-serve-random
express express-middleware hacktoberfest javascript nodejs
Last synced: about 1 month ago
JSON representation
Express middleware that responds with random files
- Host: GitHub
- URL: https://github.com/strugee/node-serve-random
- Owner: strugee
- License: lgpl-3.0
- Created: 2017-06-24T05:59:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-09-24T06:08:38.000Z (about 2 months ago)
- Last Synced: 2024-10-12T21:59:09.333Z (about 1 month ago)
- Topics: express, express-middleware, hacktoberfest, javascript, nodejs
- Language: JavaScript
- Homepage:
- Size: 188 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: COPYING
Awesome Lists containing this project
README
# node-serve-random
[![Build Status](https://travis-ci.org/strugee/node-serve-random.svg?branch=master)](http://travis-ci.org/strugee/node-serve-random)
[![Coverage Status](https://coveralls.io/repos/github/strugee/node-serve-random/badge.svg?branch=master)](https://coveralls.io/github/strugee/node-serve-random?branch=master)
[![Greenkeeper badge](https://badges.greenkeeper.io/strugee/node-serve-random.svg)](https://greenkeeper.io/)Serve random files
Vaguely API-compatible with [serve-static][].
## API
### serveRandom(root, options)
Create a new middleware function to serve files from within a given root directory. With each inbound request, a random file will be selected from the given root directory. The module will not recurse into subdirectories.
The response's max-age is always set to 0.
#### Options
##### fallthrough
Set the middleware to have errors (clients using an HTTP method other than `GET` or `HEAD`, or `root` being empty) fall-through as just unhandled requests, otherwise forward a client error. The difference is that client errors will cause this middleware to simply `next()` to your next middleware when this value is `true`. When this value is `false`, these errors (even 404s), will invoke `next(err)`.
Defaults to `true`.
## Acknowledgments
This module heavily borrows code from [serve-static][] - many thanks to the great people who work on that module.
## License
LGPL 3.0+
## Author
AJ Jordan
[serve-static]: https://github.com/expressjs/serve-static