JSPM

server-factory

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q26075F
  • License MIT

Create multiple servers based on protocols

Package Exports

  • server-factory

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (server-factory) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

server-factory

Create multiple servers on different protocols: tcp, tls, ws, wss. Emit 'stream' when there is a new connection.

Install

npm i server-factory --save

Example

'use strict'

const path = require('path')
const fs = require('fs')
const factory = require('.')

const servers = factory([{
  protocol: 'tcp',
  port: 3030
}, {
  protocol: 'ws',
  port: 3031
}, {
  protocol: 'tls',
  port: 3032,
  key: fs.readFileSync(path.join(__dirname, 'test', 'fixture', 'key.pem')),
  cert: fs.readFileSync(path.join(__dirname, 'test', 'fixture', 'cert.pem'))
}, {
  protocol: 'wss',
  port: 3036,
  key: fs.readFileSync(path.join(__dirname, 'test', 'fixture', 'key.pem')),
  cert: fs.readFileSync(path.join(__dirname, 'test', 'fixture', 'cert.pem'))
}])

servers.on('listening', function () {
  console.log('servers listening on', servers.addresses())
})

servers.on('stream', function (stream) {
  stream.pipe(stream)
})

License

MIT