@webqit/webflo 1.0.1 → 1.0.3

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.3",
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
  }
@@ -141,7 +141,7 @@ export class WebfloWorker extends WebfloRuntime {
141
141
  // Create and route request
142
142
  scope.request = this.createRequest(scope.url, scope.init);
143
143
  scope.cookies = this.constructor.CookieStorage.create(scope.request);
144
- scope.session = this.constructor.SessionStorage.create(scope.request, { secret: this.cx.env.entries.SESSION_KEY });
144
+ scope.session = this.constructor.SessionStorage.create(scope.request);
145
145
  const portID = crypto.randomUUID();
146
146
  scope.clientMessaging = new ClientMessaging(this, portID, { isPrimary: true });
147
147
  scope.user = this.constructor.HttpUser.create(
@@ -121,7 +121,7 @@ export class WebfloServer extends WebfloRuntime {
121
121
  control() {
122
122
  // ---------------
123
123
  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));
124
+ const httpServer = Http.createServer((request, response) => this.handleNodeHttpRequest(request, response));
125
125
  httpServer.listen(this.#cx.server.port);
126
126
  // -------
127
127
  let domains = parseDomains(this.#cx.server.domains);
@@ -133,12 +133,12 @@ export class WebfloServer extends WebfloRuntime {
133
133
  });
134
134
  // Handle WebSocket connections
135
135
  httpServer.on('upgrade', (request, socket, head) => {
136
- this.handleNodeWsRequest(wss, 'ws', request, socket, head);
136
+ this.handleNodeWsRequest(wss, request, socket, head);
137
137
  });
138
138
  }
139
139
  // ---------------
140
140
  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));
141
+ const httpsServer = Https.createServer((request, response) => this.handleNodeHttpRequest(request, response));
142
142
  httpsServer.listen(this.#cx.server.https.port);
143
143
  // -------
144
144
  const addSSLContext = (serverConfig, domains) => {
@@ -164,15 +164,22 @@ export class WebfloServer extends WebfloRuntime {
164
164
  }
165
165
  // Handle WebSocket connections
166
166
  httpsServer.on('upgrade', (request, socket, head) => {
167
- this.handleNodeWsRequest(wss, 'wss', request, socket, head);
167
+ this.handleNodeWsRequest(wss, request, socket, head);
168
168
  });
169
169
  }
170
170
  // ---------------
171
171
  const wss = new WebSocket.Server({ noServer: true });
172
172
  }
173
173
 
174
+ getRequestProto(nodeRequest) {
175
+ return nodeRequest.connection.encrypted ? 'https' : (nodeRequest.headers['x-forwarded-proto'] || 'http');
176
+ }
177
+
174
178
  #globalMessagingRegistry = new Map;
175
- async handleNodeWsRequest(wss, proto, nodeRequest, socket, head) {
179
+ async handleNodeWsRequest(wss, nodeRequest, socket, head) {
180
+ const proto = this.getRequestProto(nodeRequest);
181
+ console.log('__________ws:', proto);
182
+
176
183
  const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest, false);
177
184
  const scope = {};
178
185
  scope.url = new URL(fullUrl);
@@ -231,7 +238,10 @@ export class WebfloServer extends WebfloRuntime {
231
238
  }
232
239
  }
233
240
 
234
- async handleNodeHttpRequest(proto, nodeRequest, nodeResponse) {
241
+ async handleNodeHttpRequest(nodeRequest, nodeResponse) {
242
+ const proto = this.getRequestProto(nodeRequest);
243
+ console.log('__________http:', proto);
244
+
235
245
  const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest);
236
246
  const scope = {};
237
247
  scope.url = new URL(fullUrl);
@@ -570,7 +580,6 @@ export class WebfloServer extends WebfloRuntime {
570
580
  const is404 = response.status === 404;
571
581
  if (is404) return response;
572
582
  const acceptedOrUnchanged = [202/*Accepted*/, 304/*Not Modified*/].includes(response.status);
573
- const t = response.status === 404;
574
583
  if (httpEvent.request.headers.get('Accept')) {
575
584
  const requestAccept = httpEvent.request.headers.get('Accept', true);
576
585
  if (requestAccept.match('text/html') && !response.meta.static) {
@@ -585,9 +594,6 @@ export class WebfloServer extends WebfloRuntime {
585
594
  // Satisfy "Range" header
586
595
  if (httpEvent.request.headers.get('Range') && !response.headers.get('Content-Range')
587
596
  && (response.body instanceof ReadableStream || ArrayBuffer.isView(response.body))) {
588
- if (t) {
589
- console.log(httpEvent.request.url, response.body);
590
- }
591
597
  const rangeRequest = httpEvent.request.headers.get('Range', true);
592
598
  const body = _ReadableStream.from(response.body);
593
599
  // ...in partials