Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/little-core-labs/random-access-http-server
Server and middleware to serve read only random access storages over HTTP.
https://github.com/little-core-labs/random-access-http-server
access http middleware random server storage
Last synced: 3 days ago
JSON representation
Server and middleware to serve read only random access storages over HTTP.
- Host: GitHub
- URL: https://github.com/little-core-labs/random-access-http-server
- Owner: little-core-labs
- License: mit
- Created: 2019-11-21T20:17:55.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-21T13:49:47.000Z (almost 5 years ago)
- Last Synced: 2025-01-04T15:46:05.428Z (11 days ago)
- Topics: access, http, middleware, random, server, storage
- Language: JavaScript
- Size: 19.5 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
random-access-http-server
=========================> Server and middleware to serve read only random access storages over HTTP.
## Status
> **Stable**
> [![Actions Status](https://github.com/little-core-labs/random-access-http-server/workflows/Node%20CI/badge.svg)](https://github.com/little-core-labs/random-access-http-server/actions)
## Installation
```sh
$ npm install random-access-http-server
```## Usage
```js
const { createServer } = require('random-access-http-server')
const raf = require('random-access-file')
const server = createServer({
storage(pathname, opts, req, res) {
// return `random-access-storage` compliant object based
// on `pathname` from the request URL
return raf(pathname)
}
})
``````js
const http = request('http')
const raf = require('random-access-file')
const onrequest = require('random-access-http-server/middleware')({
storage(pathname, opts, req, res) {
// same as above
return raf(pathname)
}
})const server = http.createServer(onrequest)
```## API
### `const server = createServer(opts)`Creates a new
[`http.Server`](https://nodejs.org/api/http.html#http_class_http_server)
instance with `opts` passed directly to
[`middleware(opts)`](#api-middleware).
### `const onrequest = middleware(opts)`Creates a new middleware function (`onrequest(req, res, next)`) suitable
for handling
[request](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
and [response](https://nodejs.org/api/http.html#http_class_http_serverresponse)
objects from a
[`http.Server`](https://nodejs.org/api/http.html#http_class_http_server).## License
MIT