@plant/https2

1.0.2 • Public • Published

Node HTTP2 TLS/SSL server for Plant

Plant adapter for node.js http2 module. It creates server listener from plant instance and http2.createSecureServer() options.

Install

npm i @plant/https2

Usage

Hello World Example

// Build request handler
const Plant = require('@plant/plant');
const {createServer} = require('@plant/https2');

const plant = new Plant();
plant.use(({res, socket}) => {
  res.body = 'Hello, World!'
})

createServer(plant, {
  // get SSL key and cert somehow
  key,
  cert,
}).listen(443)

Enable HTTP1

HTTP package doesn't support HTTP1 support by default and you should enable it manually:

createServer(plant, {
  allowHTTP1: true,
})

HTTP2 Push Example

plant.use(({res, socket}) => {
  // Send HTTP2 push
  if (socket.canPush) {
    res.push(new Response({
      url: new URL('/style.css', res.url),
      headers: {
        'content-type': 'text/css',
      },
      body: 'html {color: green}',
    }))
  }

  res.body = '<html><head><link href="/style.css" ...'
})

Copyright

MIT © Rumkin

Readme

Keywords

Package Sidebar

Install

npm i @plant/https2

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

4.57 kB

Total Files

5

Last publish

Collaborators

  • rumkin