@webqit/webflo 1.0.1 → 1.0.2

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/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "vanila-javascript"
13
13
  ],
14
14
  "homepage": "https://webqit.io/tooling/webflo",
15
- "version": "1.0.1",
15
+ "version": "1.0.2",
16
16
  "license": "MIT",
17
17
  "repository": {
18
18
  "type": "git",
@@ -1,5 +1,6 @@
1
1
  import { WebfloClient } from './WebfloClient.js';
2
2
  import { Context } from './Context.js';
3
+ import { Workport } from './Workport.js';
3
4
 
4
5
  const { Observer } = webqit;
5
6
 
@@ -7,6 +8,8 @@ export class WebfloRootClient1 extends WebfloClient {
7
8
 
8
9
  static get Context() { return Context; }
9
10
 
11
+ static get Workport() { return Workport; }
12
+
10
13
  static create(host, cx = {}) {
11
14
  return new this(host, this.Context.create(cx));
12
15
  }
@@ -73,7 +76,8 @@ export class WebfloRootClient1 extends WebfloClient {
73
76
  PUSH_REGISTRATION_PUBLIC_URL: this.cx.params.env[push_registration_url_env],
74
77
  startMessages: true
75
78
  };
76
- //this.workport.registerServiceWorker(base + filename, swParams);
79
+ this.workport = new this.constructor.Workport;
80
+ this.workport.registerServiceWorker(base + filename, swParams);
77
81
  }
78
82
  if (window.opener) {
79
83
  // Window opener pinging
@@ -19,9 +19,9 @@ export class Workport {
19
19
  const stateChange = (target) => {
20
20
  // target.state can be any of: "parsed", "installing", "installed", "activating", "activated", "redundant"
21
21
  if (target.state === 'redundant') {
22
- this.remove(target);
22
+ //this.remove(target);
23
23
  } else if (target.state === 'activated') {
24
- this.add(target);
24
+ //this.add(target);
25
25
  }
26
26
  }
27
27
  // We're always installing at first for a new service worker.
@@ -47,13 +47,14 @@ export async function generate() {
47
47
  throw new Error(`The Layout configurator "config.deployment.Env" is required in context to bundle public env.`);
48
48
  }
49
49
  const envConfig = await (new cx.config.deployment.Env(cx)).read();
50
- for (const key in envConfig.entries) {
50
+ const env = { ...envConfig.entries, ...process.env };
51
+ for (const key in env) {
51
52
  if (!key.includes('PUBLIC_') && !key.includes('_PUBLIC')) continue;
52
53
  if (clientConfig.bundle_public_env) {
53
- clientConfig.env[key] = envConfig.entries[key];
54
+ clientConfig.env[key] = env[key];
54
55
  }
55
56
  if (workerConfig.bundle_public_env) {
56
- workerConfig.env[key] = envConfig.entries[key];
57
+ workerConfig.env[key] = env[key];
57
58
  }
58
59
  }
59
60
  }
@@ -120,8 +120,9 @@ export class WebfloServer extends WebfloRuntime {
120
120
 
121
121
  control() {
122
122
  // ---------------
123
+ console.log('________port 1:', this.#cx.server.port);
123
124
  if (!this.#cx.flags['test-only'] && !this.#cx.flags['https-only'] && this.#cx.server.port) {
124
- const httpServer = Http.createServer((request, response) => this.handleNodeHttpRequest('http', request, response));
125
+ const httpServer = Http.createServer((request, response) => this.handleNodeHttpRequest(request, response));
125
126
  httpServer.listen(this.#cx.server.port);
126
127
  // -------
127
128
  let domains = parseDomains(this.#cx.server.domains);
@@ -133,12 +134,13 @@ export class WebfloServer extends WebfloRuntime {
133
134
  });
134
135
  // Handle WebSocket connections
135
136
  httpServer.on('upgrade', (request, socket, head) => {
136
- this.handleNodeWsRequest(wss, 'ws', request, socket, head);
137
+ this.handleNodeWsRequest(wss, request, socket, head);
137
138
  });
138
139
  }
139
140
  // ---------------
141
+ console.log('________port 1:', this.#cx.server.https.port);
140
142
  if (!this.#cx.flags['test-only'] && !this.#cx.flags['http-only'] && this.#cx.server.https.port) {
141
- const httpsServer = Https.createServer((request, response) => this.handleNodeHttpRequest('https', request, response));
143
+ const httpsServer = Https.createServer((request, response) => this.handleNodeHttpRequest(request, response));
142
144
  httpsServer.listen(this.#cx.server.https.port);
143
145
  // -------
144
146
  const addSSLContext = (serverConfig, domains) => {
@@ -164,15 +166,22 @@ export class WebfloServer extends WebfloRuntime {
164
166
  }
165
167
  // Handle WebSocket connections
166
168
  httpsServer.on('upgrade', (request, socket, head) => {
167
- this.handleNodeWsRequest(wss, 'wss', request, socket, head);
169
+ this.handleNodeWsRequest(wss, request, socket, head);
168
170
  });
169
171
  }
170
172
  // ---------------
171
173
  const wss = new WebSocket.Server({ noServer: true });
172
174
  }
173
175
 
176
+ getRequestProto(nodeRequest) {
177
+ console.log({ encrypted: nodeRequest.connection.encrypted, headers: nodeRequest });
178
+ return nodeRequest.connection.encrypted ? 'https' : (nodeRequest.headers['x-forwarded-proto'] || 'http');
179
+ }
180
+
174
181
  #globalMessagingRegistry = new Map;
175
- async handleNodeWsRequest(wss, proto, nodeRequest, socket, head) {
182
+ async handleNodeWsRequest(wss, nodeRequest, socket, head) {
183
+ const proto = this.getRequestProto(nodeRequest);
184
+ console.log('__________ws:', proto);
176
185
  const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest, false);
177
186
  const scope = {};
178
187
  scope.url = new URL(fullUrl);
@@ -231,7 +240,8 @@ export class WebfloServer extends WebfloRuntime {
231
240
  }
232
241
  }
233
242
 
234
- async handleNodeHttpRequest(proto, nodeRequest, nodeResponse) {
243
+ async handleNodeHttpRequest(nodeRequest, nodeResponse) {
244
+ const proto = this.getRequestProto(nodeRequest);
235
245
  const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest);
236
246
  const scope = {};
237
247
  scope.url = new URL(fullUrl);