@polylith/server 0.1.25 → 0.1.26

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.
Files changed (2) hide show
  1. package/PolylithServer.js +17 -3
  2. package/package.json +3 -2
package/PolylithServer.js CHANGED
@@ -2,6 +2,7 @@ import express from "express";
2
2
  import http from 'node:http';
3
3
  import https from 'node:https';
4
4
  import path from 'node:path/posix';
5
+ import { Server } from "socket.io";
5
6
  import cors from 'cors';
6
7
  import cookieParser from 'cookie-parser';
7
8
  import cookieSession from 'cookie-session';
@@ -9,8 +10,6 @@ import compression from 'compression';
9
10
  import cc from "@ondohers/console-colors";
10
11
  import {workingDir} from './utils.js';
11
12
 
12
-
13
-
14
13
  export class PolylithServer {
15
14
  constructor(options, dest) {
16
15
  this.options = options;
@@ -29,6 +28,14 @@ export class PolylithServer {
29
28
  }
30
29
  }
31
30
 
31
+ async setupSocketIo(apps) {
32
+ if (!this.socketIo) return;
33
+
34
+ for (let app of apps) {
35
+ await app.setSocketIo(this.socketIo);
36
+ }
37
+ }
38
+
32
39
  serve() {
33
40
  var roots = !Array.isArray(this.staticRoot) ? [this.staticRoot] : this.staticRoot;
34
41
  var staticOptions = {fallthrough: true}
@@ -49,6 +56,7 @@ export class PolylithServer {
49
56
 
50
57
  this.app = express();
51
58
 
59
+
52
60
  if (useCompression) this.app.use(compression({threshold: 5000 }))
53
61
  if (corsOptions) {
54
62
  this.app.use(cors(corsOptions));
@@ -70,12 +78,18 @@ export class PolylithServer {
70
78
  .use(express.raw())
71
79
 
72
80
  this.serve();
73
- await this.setAppRoutes(apps);
74
81
 
75
82
  if (httpsOptions)
76
83
  this.server = https.createServer(httpsOptions, this.app);
77
84
  else
78
85
  this.server = http.createServer(this.app);
86
+
87
+ if (this.options.socketIo) {
88
+ this.socketIo = new Server(this.server, this.options.socketIo);
89
+ }
90
+
91
+ await this.setAppRoutes(apps);
92
+
79
93
  }
80
94
 
81
95
  start(port) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polylith/server",
3
- "version": "0.1.25",
3
+ "version": "0.1.26",
4
4
  "description": "This is the basic polylith http/https server. It is build on top of Express.js",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -20,7 +20,8 @@
20
20
  "cookie-parser": "^1.4.6",
21
21
  "cookie-session": "^2.0.0",
22
22
  "cors": "^2.8.5",
23
- "express": "^4.18.2"
23
+ "express": "^4.18.2",
24
+ "socket.io": "^4.7.2"
24
25
  },
25
26
  "type": "module"
26
27
  }