stubborn-ws
Advanced tools
Comparing version 0.1.3 to 1.0.0
{ | ||
"name": "stubborn-ws", | ||
"version": "0.1.3", | ||
"version": "1.0.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/ybonnefond/stubborn#stubborn", |
@@ -22,3 +22,3 @@ # Stubborn | ||
```bash | ||
npm install --save-dev stubborn | ||
npm install --save-dev stubborn-ws | ||
``` | ||
@@ -28,3 +28,3 @@ | ||
```bash | ||
yarn add -D stubborn | ||
yarn add -D stubborn-ws | ||
``` | ||
@@ -31,0 +31,0 @@ |
@@ -10,3 +10,3 @@ 'use strict'; | ||
const sb = new Stubborn({ port: 0 }); | ||
const sb = new Stubborn(); | ||
@@ -13,0 +13,0 @@ expect.extend({ |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const middlewares = require('./middlewares'); | ||
const { getServerPort } = require('./utils'); | ||
@@ -12,7 +13,6 @@ class Router { | ||
this.options = Object.assign({ | ||
host: '', | ||
port: 0 | ||
host: '' | ||
}, options); | ||
this.port = this.options.port; | ||
this.port = null; | ||
this.routes = new Set(); | ||
@@ -51,9 +51,4 @@ | ||
setPort(port) { | ||
this.port = port; | ||
return this; | ||
} | ||
handle(server) { | ||
this.port = getServerPort(server); | ||
const mws = buildMiddlewares(this); | ||
@@ -60,0 +55,0 @@ mws.push(buildRequestHandler(this)); |
@@ -6,2 +6,3 @@ 'use strict'; | ||
const { METHODS } = require('./constants'); | ||
const { getServerPort } = require('./utils'); | ||
@@ -19,3 +20,2 @@ class Stubborn { | ||
this.options = Object.assign({ | ||
port: 8080, | ||
host: 'localhost', | ||
@@ -25,5 +25,5 @@ defaultHeaders: {} | ||
this.port = null; | ||
this.server = http.createServer(); | ||
this.router = new Router({ host: this.options.host, port: this.options.port }); | ||
this.router.handle(this.server); | ||
this.router = new Router({ host: this.options.host }); | ||
} | ||
@@ -39,11 +39,3 @@ | ||
getPort() { | ||
if (0 === this.options.port) { | ||
const address = this.server.address(); | ||
if (null !== address) { | ||
return address.port; | ||
} | ||
} | ||
return this.options.port; | ||
return getServerPort(this.server); | ||
} | ||
@@ -138,6 +130,7 @@ | ||
*/ | ||
start() { | ||
start(port = 0) { | ||
this.port = port; | ||
return new Promise((resolve) => { | ||
this.server.listen(this.options.port); | ||
this.router.setPort(this.getPort()); | ||
this.server.listen(this.port); | ||
this.router.handle(this.server); | ||
resolve(); | ||
@@ -144,0 +137,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
72381
31
1497
0