Browse Source

upgrade to the latest lws

master
Lloyd Brookes 6 years ago
parent
commit
4c2fc87178
  1. 5
      bin/cli.js
  2. 20
      index.js
  3. 18
      lib/cli-app.js
  4. 16
      lib/default-stack.js
  5. 140
      package-lock.json
  6. 24
      package.json
  7. 4
      test/cli.js
  8. 5
      test/test.js

5
bin/cli.js

@ -4,12 +4,7 @@ const nodeVersionMatches = require('node-version-matches')
if (nodeVersionMatches('>=8')) {
const WsCli = require('../lib/cli-app')
const cli = new WsCli()
try {
cli.start()
} catch (err) {
console.error(require('util').inspect(err, { depth: 6, colors: true }))
process.exitCode = 1
}
} else {
console.log('Sorry, this app requires node v8.0.0 or above. Please upgrade https://nodejs.org/en/')
}

20
index.js

@ -1,5 +1,4 @@
const Lws = require('lws')
const path = require('path')
/**
* @module local-web-server
@ -39,27 +38,24 @@ class LocalWebServer extends Lws {
* @param [options.ciphers] {string} - Optional cipher suite specification, replacing the default.
* @param [options.secureProtocol] {string} - Optional SSL method to use, default is "SSLv23_method".
* @param [options.stack] {string[]|Middlewares[]} - Array of feature classes, or filenames of modules exporting a feature class.
* @param [options.server] {string|ServerFactory} - Custom server factory, e.g. lws-http2.
* @param [options.websocket] {string|Websocket} - Path to a websocket module
* @param [options.moduleDir] {string[]} - One or more directories to search for modules.
* @returns {Server}
*/
listen (options) {
options = Object.assign({
moduleDir: path.resolve(__dirname, `./node_modules`),
modulePrefix: 'lws-',
getDefaultConfig () {
return Object.assign(super.getDefaultConfig(), {
moduleDir: [ __dirname, '.' ],
stack: require('./lib/default-stack')
}, options)
return super.listen(options)
})
}
}
/**
/**
* Highly-verbose debug information event stream.
*
* @event module:local-web-server#verbose
* @param key {string} - An identifying string, e.g. `server.socket.data`.
* @param value {*} - The value, e.g. `{ socketId: 1, bytesRead: '3 Kb' }`.
*/
}
}
module.exports = LocalWebServer

18
lib/cli-app.js

@ -2,20 +2,20 @@ const LwsCli = require('lws/lib/cli-app')
const path = require('path')
class WsCli extends LwsCli {
execute (options, argv) {
const commandLineArgs = require('command-line-args')
const cliOptions = commandLineArgs(this.partialDefinitions(), { camelCase: true, partial: true })
if (cliOptions.defaultStack) {
execute (options) {
if (options.defaultStack) {
const list = require('./default-stack')
this.log(list)
} else {
options = {
stack: require('./default-stack').slice(),
moduleDir: path.resolve(__dirname, `../node_modules`),
modulePrefix: 'lws-'
return super.execute(options)
}
return super.execute(options, argv)
}
getDefaultOptions () {
return Object.assign(super.getDefaultOptions(), {
stack: require('./default-stack').slice(),
moduleDir: [ path.resolve(__dirname, '..'), '.' ]
})
}
partialDefinitions () {

16
lib/default-stack.js

@ -2,16 +2,16 @@ module.exports = [
'lws-basic-auth',
'lws-body-parser',
'lws-request-monitor',
'lws-log',
'lws-cors',
'lws-json',
// 'lws-log',
// 'lws-cors',
// 'lws-json',
'lws-compress',
'lws-rewrite',
// 'lws-rewrite',
'lws-blacklist',
'lws-conditional-get',
'lws-mime',
'lws-range',
'lws-spa',
// 'lws-conditional-get',
// 'lws-mime',
// 'lws-range',
// 'lws-spa',
'lws-static',
'lws-index'
]

140
package-lock.json

@ -273,9 +273,12 @@
"dev": true
},
"basic-auth": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-1.1.0.tgz",
"integrity": "sha1-RSIe5Cn37h5QNb4/UVM/HN/SmIQ="
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz",
"integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==",
"requires": {
"safe-buffer": "5.1.2"
}
},
"batch": {
"version": "0.6.1",
@ -1550,21 +1553,14 @@
"integrity": "sha512-8ODW8TrDuMYvXRwra/Kh7/rJo9BtOfPc6qO8eAfC80CnCvSjSl0bkRM24X6/XBBEyj0v1nRUQ1LyOy3dbqOWXw=="
},
"koa-compress": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/koa-compress/-/koa-compress-2.0.0.tgz",
"integrity": "sha1-e36ykhuEd0a14SK6n1zYpnHo6jo=",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/koa-compress/-/koa-compress-3.0.0.tgz",
"integrity": "sha512-xol+LkNB1mozKJkB5Kj6nYXbJXhkLkZlXl9BsGBPjujVfZ8MsIXwU4GHRTT7TlSfUcl2DU3JtC+j6wOWcovfuQ==",
"requires": {
"bytes": "^2.3.0",
"bytes": "^3.0.0",
"compressible": "^2.0.0",
"koa-is-json": "^1.0.0",
"statuses": "^1.0.0"
},
"dependencies": {
"bytes": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-2.5.0.tgz",
"integrity": "sha1-TJQj6i0lLCcMQbK97+/5u2tiwGo="
}
}
},
"koa-conditional-get": {
@ -1682,35 +1678,12 @@
}
},
"koa-static": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/koa-static/-/koa-static-4.0.3.tgz",
"integrity": "sha512-JGmxTuPWy4bH7bt6gD/OMWkhprawvRmzJSr8TWKmTL4N7+IMv3s0SedeQi5S4ilxM9Bo6ptkCyXj/7wf+VS5tg==",
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/koa-static/-/koa-static-5.0.0.tgz",
"integrity": "sha512-UqyYyH5YEXaJrf9S8E23GoJFQZXkBVJ9zYYMPGz919MSX1KuvAcycIuS0ci150HCoPf4XQVhQ84Qf8xRPWxFaQ==",
"requires": {
"debug": "^3.1.0",
"koa-send": "^4.1.3"
},
"dependencies": {
"koa-send": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/koa-send/-/koa-send-4.1.3.tgz",
"integrity": "sha512-3UetMBdaXSiw24qM2Mx5mKmxLKw5ZTPRjACjfhK6Haca55RKm9hr/uHDrkrxhSl5/S1CKI/RivZVIopiatZuTA==",
"requires": {
"debug": "^2.6.3",
"http-errors": "^1.6.1",
"mz": "^2.6.0",
"resolve-path": "^1.4.0"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
}
}
}
"koa-send": "^5.0.0"
}
},
"lcid": {
@ -1836,9 +1809,9 @@
}
},
"lws": {
"version": "2.0.0-3",
"resolved": "https://registry.npmjs.org/lws/-/lws-2.0.0-3.tgz",
"integrity": "sha512-PMncs7nYX6JJgBvm9xmcXP3SFGtHv96VqHoFq3AOKEhXauHtcB9BwN3K4nx+MAFyOR6Qf29ekdiAfhJGqd5wrg==",
"version": "2.0.0-6",
"resolved": "https://registry.npmjs.org/lws/-/lws-2.0.0-6.tgz",
"integrity": "sha512-ouyceHrpf7TjGqKv2Rs1xjhNNV/MjlPeCnZ+TY31hRIV//qiW9vqRVgTRpRT+LIRgmRl8UV0jns0Gl2z5I6Sew==",
"requires": {
"ansi-escape-sequences": "^4.1.0",
"array-back": "^3.1.0",
@ -1856,36 +1829,36 @@
}
},
"lws-basic-auth": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/lws-basic-auth/-/lws-basic-auth-0.1.1.tgz",
"integrity": "sha512-npPpqkOFzJzB9yJ2pGXmiYOswH+0n86ro75WhromeGuNo0GfE18ZLI/VCOVWmBbeXp2pcnPIMUAdkNSgukpAww==",
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/lws-basic-auth/-/lws-basic-auth-1.0.1.tgz",
"integrity": "sha512-iK4G3x90c883Mdd4AfBnmnf++Go4YRhIP8QtJ9Ojo73pT8slx+q96FFoNRt2ScSt6Ggz6n43ClZOabYPA3RtIw==",
"requires": {
"basic-auth": "^1.1.0"
"basic-auth": "^2.0.1"
}
},
"lws-blacklist": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/lws-blacklist/-/lws-blacklist-1.0.0.tgz",
"integrity": "sha512-dUn3TVoZidFqFYWFYQgo5kWCdO5bQOsMp27AscE395oYCeifeC8fzzO3geHwYn4EHhB4wikv4wODKBx54XNW6w==",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/lws-blacklist/-/lws-blacklist-2.0.0.tgz",
"integrity": "sha512-+X4JPOBbF4k2adszM6sTYubctuqZTYo3UQAfDNkWTsDxMBeLLUSSIqKtvPlvfoJAMmSu0mvx3qDwqCFZJ2yuhA==",
"requires": {
"array-back": "^3.1.0",
"path-to-regexp": "^3.0.0"
}
},
"lws-body-parser": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/lws-body-parser/-/lws-body-parser-0.2.4.tgz",
"integrity": "sha512-XKJzbzK97TUsewIPA5J2RpEk7kRoJcL+/Du6JlwzqIq84tWuXMfiT2a4Ncj12+tRWrdY2avV6d8uLhqlHLz1yg==",
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/lws-body-parser/-/lws-body-parser-1.0.0.tgz",
"integrity": "sha512-Kv2M7PxH6zrAVnAjSjvLY71pDcKnCXaOY4fgS2IFMWbgEab2eUMHx/Z6f+SpGlFffH6PXatYKCsAgX10cJdQFw==",
"requires": {
"koa-bodyparser": "^4.2.0"
"koa-bodyparser": "^4.2.1"
}
},
"lws-compress": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/lws-compress/-/lws-compress-0.2.1.tgz",
"integrity": "sha512-14++1o6U8upi3DLx9J2O2sFELsijEJF9utoFxSH4Stoo9SdU2Cxw6BtqQTrb9SEA6O6IsApzstdMYnq8floLSg==",
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/lws-compress/-/lws-compress-1.0.0.tgz",
"integrity": "sha512-m6RLrShM8BHUHmcmUdJoEkFoz4IaCqyL+R/Mz5jngvtsqOeJfCAGS8qTkbVYAZ+BwItJXtgaOoqlcB7q+7l7AQ==",
"requires": {
"koa-compress": "^2.0.0"
"koa-compress": "^3.0.0"
}
},
"lws-conditional-get": {
@ -1906,11 +1879,11 @@
}
},
"lws-index": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/lws-index/-/lws-index-0.4.0.tgz",
"integrity": "sha512-k+mkqgMSzx1ipzVpaxsAJU4Qe7R1kp1B/u+qC+d1Y3l+auBz+bLcIxL4dYKfaxLqiz0IFwg1dZwGzVm/dd7FFw==",
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/lws-index/-/lws-index-1.0.0.tgz",
"integrity": "sha512-mUC0C1+aZcfL9KkV/1DcrrCYdshVswtDoawtYsMnqdy6Lpkbd2c2UTfnBSVBrWw2enY0djULQzPW/1CEO1Hn4A==",
"requires": {
"serve-index-75lb": "^2.0.0"
"serve-index": "^1.9.1"
}
},
"lws-json": {
@ -1944,18 +1917,11 @@
}
},
"lws-request-monitor": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/lws-request-monitor/-/lws-request-monitor-0.1.5.tgz",
"integrity": "sha512-u9eczHPowH17ftUjQ8ysutGDADNZdDD6k8wgFMzOB7/rRq1Is12lTYA4u8pfKZ8C2oyoy+HYsDSrOzTwespTlA==",
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/lws-request-monitor/-/lws-request-monitor-1.0.0.tgz",
"integrity": "sha512-5BNF3SOBb0eqJMvnmZVqJHfSATfiooGCeXqbXxaWJondAzibEY18UcEcKOv0bYEaiNF48mM89dRF5yVI/O8GGw==",
"requires": {
"byte-size": "^4.0.2"
},
"dependencies": {
"byte-size": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/byte-size/-/byte-size-4.0.4.tgz",
"integrity": "sha512-82RPeneC6nqCdSwCX2hZUz3JPOvN5at/nTEw/CMf05Smu3Hrpo9Psb7LjN+k+XndNArG1EY8L4+BM3aTM4BCvw=="
}
"byte-size": "^5.0.1"
}
},
"lws-rewrite": {
@ -1980,11 +1946,11 @@
}
},
"lws-static": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/lws-static/-/lws-static-0.5.0.tgz",
"integrity": "sha512-r3QIeJfBox/hSJLSL7TPhNSZsTKE0r4mWYHbGZ+DwrBcKbLt1ljsh5NAtmJpsqCcjYpyOuD/DlsZ0yQY9VI8bA==",
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/lws-static/-/lws-static-1.0.0.tgz",
"integrity": "sha512-r9ScyeE4ehlpRdKp6sw9evJwMPZGpbwUjVlfTbzySeTLjqhLqq4JhMS5XAZiJ5g7HHrsm9Q7e35QhLpUcbyv/g==",
"requires": {
"koa-static": "^4.0.2"
"koa-static": "^5.0.0"
}
},
"make-dir": {
@ -2136,14 +2102,6 @@
"on-headers": "~1.0.1"
},
"dependencies": {
"basic-auth": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz",
"integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==",
"requires": {
"safe-buffer": "5.1.2"
}
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@ -2793,17 +2751,17 @@
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz",
"integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA=="
},
"serve-index-75lb": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/serve-index-75lb/-/serve-index-75lb-2.0.1.tgz",
"integrity": "sha512-/d9r8bqJlFQcwy0a0nb1KnWAA+Mno+V+VaoKocdkbW5aXKRQd/+4bfnRhQRQr6uEoYwTRJ4xgztOyCJvWcpBpQ==",
"serve-index": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/serve-index/-/serve-index-1.9.1.tgz",
"integrity": "sha1-03aNabHn2C5c4FD/9bRTvqEqkjk=",
"requires": {
"accepts": "~1.3.4",
"batch": "0.6.1",
"debug": "2.6.9",
"escape-html": "~1.0.3",
"http-errors": "~1.6.2",
"mime-types": "~2.1.18",
"mime-types": "~2.1.17",
"parseurl": "~1.3.2"
},
"dependencies": {

24
package.json

@ -2,6 +2,8 @@
"name": "local-web-server",
"version": "3.0.0-1",
"description": "The modular web server for productive full-stack development",
"repository": "https://github.com/lwsjs/local-web-server",
"author": "Lloyd Brookes <75pound@gmail.com>",
"bin": {
"ws": "./bin/cli.js"
},
@ -28,30 +30,28 @@
"docs": "jsdoc2md -p list index.js lib/*.js > doc/api.md; echo",
"cover": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
},
"repository": "https://github.com/lwsjs/local-web-server",
"author": "Lloyd Brookes <75pound@gmail.com>",
"files": [
"bin",
"lib",
"bin/*.js",
"lib/*.js",
"index.js"
],
"dependencies": {
"lws": "2.0.0-3",
"lws-basic-auth": "^0.1.1",
"lws-blacklist": "^1.0.0",
"lws-body-parser": "^0.2.4",
"lws-compress": "^0.2.1",
"lws": "2.0.0-6",
"lws-basic-auth": "^1.0.1",
"lws-blacklist": "^2.0.0",
"lws-body-parser": "^1.0.0",
"lws-compress": "^1.0.0",
"lws-conditional-get": "^0.3.4",
"lws-cors": "^1.0.0",
"lws-index": "^0.4.0",
"lws-index": "^1.0.0",
"lws-json": "^0.3.2",
"lws-log": "^0.3.2",
"lws-mime": "^0.2.2",
"lws-range": "^1.1.1",
"lws-request-monitor": "^0.1.5",
"lws-request-monitor": "^1.0.0",
"lws-rewrite": "^1.0.1",
"lws-spa": "^1.0.1",
"lws-static": "^0.5.0",
"lws-static": "^1.0.0",
"node-version-matches": "^1.0.1"
},
"devDependencies": {

4
test/cli.js

@ -12,7 +12,7 @@ tom.test('cli.run', async function () {
const cli = new WsCli({ logError: function () {} })
const server = cli.start()
process.argv = origArgv
const response = await fetch(`http://127.0.0.1:${port}/`)
const response = await fetch(`http://127.0.0.1:${port}/package.json`)
server.close()
a.strictEqual(response.status, 200)
})
@ -53,6 +53,6 @@ tom.test('cli.run: default-stack', async function () {
let logMsg = ''
const cli = new WsCli({ log: function (msg) { logMsg = msg } })
cli.start()
a.ok(/lws-rewrite/.test(logMsg))
a.ok(/lws-static/.test(logMsg))
process.argv = origArgv
})

5
test/test.js

@ -7,13 +7,12 @@ const tom = module.exports = new Tom('test')
tom.test('basic', async function () {
const port = 9000 + this.index
const localWebServer = new LocalWebServer()
const server = localWebServer.listen({
const ws = LocalWebServer.create({
port: port,
directory: 'test/fixture'
})
const response = await fetch(`http://localhost:${port}/one.txt`)
server.close()
ws.server.close()
const body = await response.text()
a.strictEqual(body, 'one\n')
})
Loading…
Cancel
Save