Skip to content

Commit 4c2fc87

Browse files
committedJun 2, 2019
upgrade to the latest lws
1 parent bba4314 commit 4c2fc87

File tree

8 files changed

+97
-149
lines changed

8 files changed

+97
-149
lines changed
 

‎bin/cli.js

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

‎index.js

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const Lws = require('lws')
2-
const path = require('path')
32

43
/**
54
* @module local-web-server
@@ -39,27 +38,24 @@ class LocalWebServer extends Lws {
3938
* @param [options.ciphers] {string} - Optional cipher suite specification, replacing the default.
4039
* @param [options.secureProtocol] {string} - Optional SSL method to use, default is "SSLv23_method".
4140
* @param [options.stack] {string[]|Middlewares[]} - Array of feature classes, or filenames of modules exporting a feature class.
42-
* @param [options.server] {string|ServerFactory} - Custom server factory, e.g. lws-http2.
43-
* @param [options.websocket] {string|Websocket} - Path to a websocket module
4441
* @param [options.moduleDir] {string[]} - One or more directories to search for modules.
4542
* @returns {Server}
4643
*/
47-
listen (options) {
48-
options = Object.assign({
49-
moduleDir: path.resolve(__dirname, `./node_modules`),
50-
modulePrefix: 'lws-',
51-
stack: require('./lib/default-stack')
52-
}, options)
53-
return super.listen(options)
5444

55-
/**
56-
* Highly-verbose debug information event stream.
57-
*
58-
* @event module:local-web-server#verbose
59-
* @param key {string} - An identifying string, e.g. `server.socket.data`.
60-
* @param value {*} - The value, e.g. `{ socketId: 1, bytesRead: '3 Kb' }`.
61-
*/
45+
getDefaultConfig () {
46+
return Object.assign(super.getDefaultConfig(), {
47+
moduleDir: [ __dirname, '.' ],
48+
stack: require('./lib/default-stack')
49+
})
6250
}
6351
}
6452

53+
/**
54+
* Highly-verbose debug information event stream.
55+
*
56+
* @event module:local-web-server#verbose
57+
* @param key {string} - An identifying string, e.g. `server.socket.data`.
58+
* @param value {*} - The value, e.g. `{ socketId: 1, bytesRead: '3 Kb' }`.
59+
*/
60+
6561
module.exports = LocalWebServer

‎lib/cli-app.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ const LwsCli = require('lws/lib/cli-app')
22
const path = require('path')
33

44
class WsCli extends LwsCli {
5-
execute (options, argv) {
6-
const commandLineArgs = require('command-line-args')
7-
const cliOptions = commandLineArgs(this.partialDefinitions(), { camelCase: true, partial: true })
8-
if (cliOptions.defaultStack) {
5+
execute (options) {
6+
if (options.defaultStack) {
97
const list = require('./default-stack')
108
this.log(list)
119
} else {
12-
options = {
13-
stack: require('./default-stack').slice(),
14-
moduleDir: path.resolve(__dirname, `../node_modules`),
15-
modulePrefix: 'lws-'
16-
}
17-
return super.execute(options, argv)
10+
return super.execute(options)
1811
}
1912
}
2013

14+
getDefaultOptions () {
15+
return Object.assign(super.getDefaultOptions(), {
16+
stack: require('./default-stack').slice(),
17+
moduleDir: [ path.resolve(__dirname, '..'), '.' ]
18+
})
19+
}
20+
2121
partialDefinitions () {
2222
return super.partialDefinitions().concat([
2323
{

‎lib/default-stack.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ module.exports = [
22
'lws-basic-auth',
33
'lws-body-parser',
44
'lws-request-monitor',
5-
'lws-log',
6-
'lws-cors',
7-
'lws-json',
5+
// 'lws-log',
6+
// 'lws-cors',
7+
// 'lws-json',
88
'lws-compress',
9-
'lws-rewrite',
9+
// 'lws-rewrite',
1010
'lws-blacklist',
11-
'lws-conditional-get',
12-
'lws-mime',
13-
'lws-range',
14-
'lws-spa',
11+
// 'lws-conditional-get',
12+
// 'lws-mime',
13+
// 'lws-range',
14+
// 'lws-spa',
1515
'lws-static',
1616
'lws-index'
1717
]

‎package-lock.json

+49-91
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"name": "local-web-server",
33
"version": "3.0.0-1",
44
"description": "The modular web server for productive full-stack development",
5+
"repository": "https://github.com/lwsjs/local-web-server",
6+
"author": "Lloyd Brookes <75pound@gmail.com>",
57
"bin": {
68
"ws": "./bin/cli.js"
79
},
@@ -28,30 +30,28 @@
2830
"docs": "jsdoc2md -p list index.js lib/*.js > doc/api.md; echo",
2931
"cover": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
3032
},
31-
"repository": "https://github.com/lwsjs/local-web-server",
32-
"author": "Lloyd Brookes <75pound@gmail.com>",
3333
"files": [
34-
"bin",
35-
"lib",
34+
"bin/*.js",
35+
"lib/*.js",
3636
"index.js"
3737
],
3838
"dependencies": {
39-
"lws": "2.0.0-3",
40-
"lws-basic-auth": "^0.1.1",
41-
"lws-blacklist": "^1.0.0",
42-
"lws-body-parser": "^0.2.4",
43-
"lws-compress": "^0.2.1",
39+
"lws": "2.0.0-6",
40+
"lws-basic-auth": "^1.0.1",
41+
"lws-blacklist": "^2.0.0",
42+
"lws-body-parser": "^1.0.0",
43+
"lws-compress": "^1.0.0",
4444
"lws-conditional-get": "^0.3.4",
4545
"lws-cors": "^1.0.0",
46-
"lws-index": "^0.4.0",
46+
"lws-index": "^1.0.0",
4747
"lws-json": "^0.3.2",
4848
"lws-log": "^0.3.2",
4949
"lws-mime": "^0.2.2",
5050
"lws-range": "^1.1.1",
51-
"lws-request-monitor": "^0.1.5",
51+
"lws-request-monitor": "^1.0.0",
5252
"lws-rewrite": "^1.0.1",
5353
"lws-spa": "^1.0.1",
54-
"lws-static": "^0.5.0",
54+
"lws-static": "^1.0.0",
5555
"node-version-matches": "^1.0.1"
5656
},
5757
"devDependencies": {

‎test/cli.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tom.test('cli.run', async function () {
1212
const cli = new WsCli({ logError: function () {} })
1313
const server = cli.start()
1414
process.argv = origArgv
15-
const response = await fetch(`http://127.0.0.1:${port}/`)
15+
const response = await fetch(`http://127.0.0.1:${port}/package.json`)
1616
server.close()
1717
a.strictEqual(response.status, 200)
1818
})
@@ -53,6 +53,6 @@ tom.test('cli.run: default-stack', async function () {
5353
let logMsg = ''
5454
const cli = new WsCli({ log: function (msg) { logMsg = msg } })
5555
cli.start()
56-
a.ok(/lws-rewrite/.test(logMsg))
56+
a.ok(/lws-static/.test(logMsg))
5757
process.argv = origArgv
5858
})

‎test/test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ const tom = module.exports = new Tom('test')
77

88
tom.test('basic', async function () {
99
const port = 9000 + this.index
10-
const localWebServer = new LocalWebServer()
11-
const server = localWebServer.listen({
10+
const ws = LocalWebServer.create({
1211
port: port,
1312
directory: 'test/fixture'
1413
})
1514
const response = await fetch(`http://localhost:${port}/one.txt`)
16-
server.close()
15+
ws.server.close()
1716
const body = await response.text()
1817
a.strictEqual(body, 'one\n')
1918
})

0 commit comments

Comments
 (0)
Please sign in to comment.