0.5.0 • Published 3 months ago

stream-statics v0.5.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

stream-statics

Lightweight webserver for testing and demonstrating front-end projects, running HTTP, HTTPS or HTTP/2.

Mime types

A limited set of common mime-types is used. When you install the mime-types package next to stream-statics all known mime-types can be used. This way the number of dependencies is limited.

Configuration

Before setting up a new server, a few checks are made. When the port number is in use or when the root folder can't be found, the startServer function will error.

Secure serving

On first secure run, or when the certificate has expired, a private key and a certificate are generated inside the module folder

Usage

Default configuration:

root: './',
protocol: 'http2', // 'http' | 'https' | 'http2'
port: 9630,

Start a server for instance before starting a e2e test

"scripts": {
    "...": "...",
    "pretest": "stst --port 3001 --protocol http",
    "...": "..."
}

On the command line:

npx stst --https --4210 --../../yourProject
...
kill $(lsof -t -i:4210)

In a script:

import { startServer } from 'stream-statics'

const config = {
    root: './', // default folderName
    protocol: 'http2', // default protocol
    port: 9630, // default portNumber
}
const server = startServer(config) // argument is required for now.
...
const callback = () => console.log(`Connection to localhost:${config.port} was closed`)
server.close(callback)

Demo

Run

npm run demo
0.5.0

3 months ago

0.4.0

4 months ago

0.3.0

11 months ago

0.2.0

11 months ago

0.1.0

12 months ago