Fast Stream
Fast Stream HTTP Server
$ npm install fast-stream
Simple server configuration conf
, serve all requests with 200
OK.
const http = ;const conf = '*': // host name "*" <for all>, "cb" is the callback function 404: ;; // or 443 for HTTPS / SSL
Create conf
using fast-config module for static files.
const get = ;const http = ;const conf = '*': // static files directory;;
Sample conf
for files or readable streams, mimehttp optional.
const fs = ;const mime = ;const conf = '*': GET: // method GET ;
Function host
arguments cb
, req
and this
bind example.
const conf = 'localhost:80': // hostname "localhost" port "80" GET: // URL: http://localhost/ POST: // URL: http://localhost/attach.html (method POST only) { ; // default 'Content-Type' is 'text/html' utf8 } '127.0.0.1:80': // another host GET: // URL: http://127.0.0.1/ ;
http (config, options)
class
config
Object - host functions list, see the examples aboveoptions
Object - see below
host (cb, req)
host function
cb
Function - callback function, see belowreq
Object - request, see belowthis
Bind Object - this Stream
cb (data, headers, code)
callback function
data
String|Buffer|Object - response, forObject
see belowheaders
Object - optional, default nullcode
Number - optional, http status, default 200
data
Object response
src
String|Object -String
file path orObject
readable streamlength
Number - optional, data size, required for range bytes whensrc
is readable stream
req
Object request
path
Stringquery
Object - headerquerystring
host
Stringhostname
Stringport
Numberattach
Object - whenreq.request.method
isPOST
, see belowrequest
Object - {method
: String,uri
: String,protocol
: String }header
Object - {list
: Array,hostname
: String,port
: Number,length
: Number,connection
: String,type
: String,boundary
: String,etag
: String,modified
: String,range
: String }
req.attach
Object attach
- when
req.header.type
isurlencoded
- Objectquerystring
fromPOST
body - when
req.header.type
ismultipart
- Object { query: Objectquerystring
, files: Array Object { name: String, data: Buffer } }
options
Object http class argument
limit
Number - anti memory overhead, request data maximum size, default5e8
~500MB, for big data/files, consider to increase this valueranges
Boolean - accept ranges request, defaulttrue
error
String - custom error name event, defaulthttpError
name
String - Server name/version, defaultfast-stream/2.2
,null
- to disablecache
Boolean - client cache, send/verify "Last-Modified" and/or "ETag" header, defaulttrue
closeOnError
Boolean - close connection on statuscode
>=400
, defaultfalse
, don't closechunked
Number - if body response size is greater than this value, send "Transfer-Encoding: chunked", default2e7
~20MB,0
- to disable
Fast Stream is licensed under the MIT license. See the included LICENSE
file for more details.