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.

54 lines
2.5 KiB

8 years ago
8 years ago
8 years ago
8 years ago
  1. const Lws = require('lws')
  2. const path = require('path')
  3. /**
  4. * @module local-web-server
  5. * @example
  6. * const LocalWebServer = require('local-web-server')
  7. * const localWebServer = new LocalWebServer()
  8. * const server = localWebServer.listen({
  9. * port: port,
  10. * directory: 'src'
  11. * })
  12. */
  13. /**
  14. * @alias module:local-web-server
  15. */
  16. class LocalWebServer extends Lws {
  17. /**
  18. * Create a listening HTTP/HTTPS server.
  19. * @param [options] {object} - Server options
  20. * @param [options.port] {number} - Port
  21. * @param [options.hostname] {string} -The hostname (or IP address) to listen on. Defaults to 0.0.0.0.
  22. * @param [options.maxConnections] {number} - The maximum number of concurrent connections supported by the server.
  23. * @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.
  24. * @param [options.configFile] {string} - Config file path, defaults to 'lws.config.js'.
  25. * @param [options.https] {boolean} - Enable HTTPS using a built-in key and cert registered to the domain 127.0.0.1.
  26. * @param [options.key] {string} - SSL key file path. Supply along with --cert to launch a https server.
  27. * @param [options.cert] {string} - SSL cert file path. Supply along with --key to launch a https server.
  28. * @param [options.pfx] {string} - Path to an PFX or PKCS12 encoded private key and certificate chain. An alternative to providing --key and --cert.
  29. * @param [options.ciphers] {string} - Optional cipher suite specification, replacing the default.
  30. * @param [options.secureProtocol] {string} - Optional SSL method to use, default is "SSLv23_method".
  31. * @param [options.stack] {string[]|Middlewares[]} - Array of feature classes, or filenames of modules exporting a feature class.
  32. * @param [options.server] {string|ServerFactory} - Custom server factory, e.g. lws-http2.
  33. * @param [options.websocket] {string|Websocket} - Path to a websocket module
  34. * @param [options.moduleDir] {string[]} - One or more directories to search for feature modules.
  35. * @returns {Server}
  36. */
  37. listen (options) {
  38. const usage = require('lws/lib/usage')
  39. usage.defaults
  40. .set('an', 'ws')
  41. .set('av', require('../package').version)
  42. .set('cd4', 'api')
  43. options = Object.assign({
  44. moduleDir: path.resolve(__dirname, `../node_modules`),
  45. modulePrefix: 'lws-',
  46. stack: require('./default-stack')
  47. }, options)
  48. return super.listen(options)
  49. }
  50. }
  51. module.exports = LocalWebServer