You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.6 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. const Lws = require('lws')
  2. /**
  3. * @module local-web-server
  4. * @emits module:local-web-server#verbose
  5. * @example
  6. * const LocalWebServer = require('local-web-server')
  7. * const localWebServer = new LocalWebServer()
  8. * const server = localWebServer.listen({
  9. * port: 8050,
  10. * https: true,
  11. * directory: 'src',
  12. * spa: 'index.html',
  13. * websocket: 'src/websocket-server.js'
  14. * })
  15. * // secure, SPA server with listening websocket now ready on port 8050
  16. *
  17. * // shut down the server
  18. * server.close()
  19. */
  20. /**
  21. * @alias module:local-web-server
  22. */
  23. class LocalWebServer extends Lws {
  24. /**
  25. * Returns a listening HTTP/HTTPS server.
  26. * @param [options] {object} - Server options
  27. * @param [options.port] {number} - Port
  28. * @param [options.hostname] {string} -The hostname (or IP address) to listen on. Defaults to 0.0.0.0.
  29. * @param [options.maxConnections] {number} - The maximum number of concurrent connections supported by the server.
  30. * @param [options.keepAliveTimeout] {number} - The period (in milliseconds) of inactivity a connection will remain open before being destroyed. Set to `0` to keep connections open indefinitely.
  31. * @param [options.configFile] {string} - Config file path, defaults to 'lws.config.js'.
  32. * @param [options.https] {boolean} - Enable HTTPS using a built-in key and cert registered to the domain 127.0.0.1.
  33. * @param [options.key] {string} - SSL key file path. Supply along with --cert to launch a https server.
  34. * @param [options.cert] {string} - SSL cert file path. Supply along with --key to launch a https server.
  35. * @param [options.pfx] {string} - Path to an PFX or PKCS12 encoded private key and certificate chain. An alternative to providing --key and --cert.
  36. * @param [options.ciphers] {string} - Optional cipher suite specification, replacing the default.
  37. * @param [options.secureProtocol] {string} - Optional SSL method to use, default is "SSLv23_method".
  38. * @param [options.stack] {string[]|Middlewares[]} - Array of feature classes, or filenames of modules exporting a feature class.
  39. * @param [options.moduleDir] {string[]} - One or more directories to search for modules.
  40. * @returns {Server}
  41. */
  42. getDefaultConfig () {
  43. return Object.assign(super.getDefaultConfig(), {
  44. moduleDir: [ __dirname, '.' ],
  45. stack: require('./lib/default-stack')
  46. })
  47. }
  48. }
  49. /**
  50. * Highly-verbose debug information event stream.
  51. *
  52. * @event module:local-web-server#verbose
  53. * @param key {string} - An identifying string, e.g. `server.socket.data`.
  54. * @param value {*} - The value, e.g. `{ socketId: 1, bytesRead: '3 Kb' }`.
  55. */
  56. module.exports = LocalWebServer