redweb 0.7.6 → 0.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,7 +29,7 @@ const {
29
29
 
30
30
  ## HTTP servers (Express)
31
31
 
32
- `new HttpServer(options)` starts listening immediately (default port `80`). `new HttpsServer({ ssl: { key, cert }, ... })` does the same over TLS.
32
+ `new HttpServer(options)` creates a Node HTTP server and starts listening immediately by default (default port `80`). `new HttpsServer({ ssl: { key, cert }, ... })` does the same over TLS.
33
33
 
34
34
  Options:
35
35
 
@@ -37,7 +37,7 @@ Options:
37
37
  - `bind` (string): defaults to `0.0.0.0`.
38
38
  - `publicPaths` (string[]): folders served as static assets.
39
39
  - `services` (array): `{ serviceName, method, function }` for REST endpoints.
40
- - `listen` (boolean): defaults to `true`; set `false` to build `.app` without binding a port.
40
+ - `listen` (boolean): defaults to `true`; set `false` to build `.app` and `.server` without binding a port.
41
41
  - `listenCallback` (function): invoked after `.listen`.
42
42
  - `encoding` (`'json' | 'urlencoded'`): body parser selection.
43
43
  - `corsOptions`: passed to `cors`.
@@ -206,10 +206,9 @@ class ClipboardRoute extends SocketRoute {
206
206
 
207
207
  ### Sharing an HTTP/HTTPS server
208
208
 
209
- Use `listen: false` on `HttpServer` to build the Express app without binding a port. Then create one Node server from `httpServer.app` and pass it to `SocketServer`. When `SocketServer` receives a prebuilt `server`, it attaches upgrade handling but does not call `.listen()` unless you explicitly set `listen: true`.
209
+ Use `listen: false` on `HttpServer` to build the Express app and Node server without binding a port. Then pass `httpServer.server` to `SocketServer`. When `SocketServer` receives a prebuilt `server`, it attaches upgrade handling but does not call `.listen()` unless you explicitly set `listen: true`.
210
210
 
211
211
  ```js
212
- const http = require('http');
213
212
  const { HttpServer, METHODS, SocketServer } = require('redweb');
214
213
 
215
214
  const httpServer = new HttpServer({
@@ -222,14 +221,12 @@ const httpServer = new HttpServer({
222
221
  ]
223
222
  });
224
223
 
225
- const server = http.createServer(httpServer.app);
226
-
227
224
  new SocketServer({
228
- server,
225
+ server: httpServer.server,
229
226
  routes: [ClipboardRoute]
230
227
  });
231
228
 
232
- server.listen(3030, () => console.log('HTTP and WebSocket server listening on 3030'));
229
+ httpServer.server.listen(3030, () => console.log('HTTP and WebSocket server listening on 3030'));
233
230
  ```
234
231
 
235
232
  ### Socket services
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redweb",
3
- "version": "0.7.6",
3
+ "version": "0.7.7",
4
4
  "description": "A way to quickly set up an express server",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,4 +1,5 @@
1
- const { BaseHttpServer } = require('./BaseHttpServer');
1
+ const http = require('http');
2
+ const { BaseHttpServer } = require('./BaseHttpServer');
2
3
 
3
4
  /**
4
5
  * HTTP Server
@@ -7,11 +8,10 @@ const { BaseHttpServer } = require('./BaseHttpServer');
7
8
  */
8
9
  function HttpServer(options = {}) {
9
10
  BaseHttpServer.call(this, options);
10
- if (this.listen === false) {
11
- return this;
11
+ this.server = http.createServer(this.app);
12
+ if (this.listen !== false) {
13
+ this.server.listen(this.port, this.listenCallback ? this.listenCallback : () => console.log(`RedWeb HttpServer listening on port ${this.port}`));
12
14
  }
13
-
14
- this.server = this.app.listen(this.port, this.listenCallback ? this.listenCallback : () => console.log(`RedWeb HttpServer listening on port ${this.port}`));
15
15
  return this;
16
16
  }
17
17