Skip to content
This repository has been archived by the owner on Feb 10, 2019. It is now read-only.
/ hh2 Public archive

A wrapper to create instances of node http, https and http2 servers

License

Notifications You must be signed in to change notification settings

ramlmn/hh2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hh2

A zero-dependency wrapper to create various instances of node http interfaces.

Usage

const options = {
  h2: Boolean
  secure: Boolean,
  ..., // other options for the server
};

const server = hh2(app, options);

The app is a requestListener for node http request.

The h2 options is used to create http2 server and the secure option is to create a secureServer variant of http or http2. By default a http server is created.

Simply put, hh2 creates the appropriate server and returns an instance of net.Server.

https server

const express = require('express');
const hh2 = require('@ramlmn/hh2');
const app = express();

const server = hh2(app, {
  secure: true,           // <- explicit https

  // certs as options
  key: fs.readFileSync('server-key.pem'),
  cert: fs.readFileSync('server-cert.pem'),
});

server.listen( _ => {
  console.log('> Server started');
});

http2 server

const express = require('express');
const hh2 = require('@ramlmn/hh2');
const app = express();

const server = hh2(app, {
  h2: true                // <- explicit http2
  secure: true,

  // http2 in SSL
  key: fs.readFileSync('server-key.pem'),
  cert: fs.readFileSync('server-cert.pem'),
});

server.listen(_ => {
  console.log('> Server started');
});

License

MIT