项目作者: ramlmn

项目描述 :
A wrapper to create instances of node http, https and http2 servers
高级语言: JavaScript
项目地址: git://github.com/ramlmn/hh2.git
创建时间: 2018-04-04T18:22:23Z
项目社区:https://github.com/ramlmn/hh2

开源协议:MIT License

下载


hh2

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

Usage

  1. const options = {
  2. h2: Boolean
  3. secure: Boolean,
  4. ..., // other options for the server
  5. };
  6. 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

  1. const express = require('express');
  2. const hh2 = require('@ramlmn/hh2');
  3. const app = express();
  4. const server = hh2(app, {
  5. secure: true, // <- explicit https
  6. // certs as options
  7. key: fs.readFileSync('server-key.pem'),
  8. cert: fs.readFileSync('server-cert.pem'),
  9. });
  10. server.listen( _ => {
  11. console.log('> Server started');
  12. });

http2 server

  1. const express = require('express');
  2. const hh2 = require('@ramlmn/hh2');
  3. const app = express();
  4. const server = hh2(app, {
  5. h2: true // <- explicit http2
  6. secure: true,
  7. // http2 in SSL
  8. key: fs.readFileSync('server-key.pem'),
  9. cert: fs.readFileSync('server-cert.pem'),
  10. });
  11. server.listen(_ => {
  12. console.log('> Server started');
  13. });

License

MIT