Streaming static file server based on LevelDB.
Store and serve a nice cat picture at
var Server = ;var level = ;var http = ;var fs = ;// initialize db and servervar db = ;var server = ;// store catvar ws = server;fs;// serve cathttp;console;
ETags are used to save bandwidth and reduce load.
With sublevels you can e.g. give a plugin or a user only access to a part of the database so they can't do anything harmful. The location in the sublevel tree is reflected in the resulting public url.
This concept involves two instances of
- One is read only and serves the whole database over http.
- The other one is given to clients / plugins and they can write whatever they want, however only see their own section of the db, their sublevel.
var Server = ;var level = ;var http = ;var SubLevel = ;var fs = ;// initialize the db and give it sublevelsvar db = ;;// initialize server for sublevelvar server = ;// cat from sublevel "cool"."cats" will be served at /files/cool/cats/white.pngvar ws = server;fs;// serve catvar dbServer = ;http;console;
/files/ (sublevels /) file-id
Generate URLs using
Make sure that
db has been opened with
valueEncoding: 'binary' if you want
to serve binary files.
Server#handle(req, res[, next])
HTTP request handler. Pass this to
next is passed it will be called when errors happen or a requested file
cannot be found.
Store a file under
file-id. If you give
file-id an extension it will be
served with the correct mime type.
Retrieve a file stored under
Server#store(file-id, data[, cb])
file-id. Convenience method that exposes the write stream
in an async api.
Get the url of
file-id, respecting sublevels.
With npm do
$ npm install level-serve
Copyright (c) 2013 Wayla <email@example.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.