random-access-http-server

1.2.0 • Public • Published

random-access-http-server

Server and middleware to serve read only random access storages over HTTP.

Status

Stable

Actions Status

Installation

$ npm install random-access-http-server

Usage

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)
  }
})
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 instance with opts passed directly to middleware(opts).

const onrequest = middleware(opts)

Creates a new middleware function (onrequest(req, res, next)) suitable for handling request and response objects from a http.Server.

License

MIT

Package Sidebar

Install

npm i random-access-http-server

Weekly Downloads

6

Version

1.2.0

License

MIT

Unpacked Size

12 kB

Total Files

9

Last publish

Collaborators

  • werle