@webqit/webflo 1.0.0 → 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
|
@@ -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
|
-
|
|
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.
|
|
@@ -26,10 +26,12 @@ export async function generate() {
|
|
|
26
26
|
throw new Error(`The Client configurator "config.deployment.Layout" is required in context.`);
|
|
27
27
|
}
|
|
28
28
|
const clientConfig = await (new cx.config.runtime.Client(cx)).read();
|
|
29
|
+
clientConfig.env = {};
|
|
29
30
|
if (clientConfig.service_worker?.filename && !cx.config.runtime.client?.Worker) {
|
|
30
31
|
throw new Error(`The Service Worker configurator "config.runtime.client.Worker" is required in context.`);
|
|
31
32
|
}
|
|
32
33
|
const workerConfig = await (new cx.config.runtime.client.Worker(cx)).read();
|
|
34
|
+
workerConfig.env = {};
|
|
33
35
|
// -----------
|
|
34
36
|
if (!cx.config.deployment?.Layout) {
|
|
35
37
|
throw new Error(`The Layout configurator "config.deployment.Layout" is required in context.`);
|
|
@@ -45,15 +47,14 @@ export async function generate() {
|
|
|
45
47
|
throw new Error(`The Layout configurator "config.deployment.Env" is required in context to bundle public env.`);
|
|
46
48
|
}
|
|
47
49
|
const envConfig = await (new cx.config.deployment.Env(cx)).read();
|
|
48
|
-
|
|
50
|
+
const env = { ...envConfig.entries, ...process.env };
|
|
51
|
+
for (const key in env) {
|
|
49
52
|
if (!key.includes('PUBLIC_') && !key.includes('_PUBLIC')) continue;
|
|
50
53
|
if (clientConfig.bundle_public_env) {
|
|
51
|
-
|
|
52
|
-
clientConfig.env[key] = envConfig.entries[key];
|
|
54
|
+
clientConfig.env[key] = env[key];
|
|
53
55
|
}
|
|
54
56
|
if (workerConfig.bundle_public_env) {
|
|
55
|
-
|
|
56
|
-
workerConfig.env[key] = envConfig.entries[key];
|
|
57
|
+
workerConfig.env[key] = env[key];
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
}
|
|
@@ -3,8 +3,8 @@ import { WebfloRootClient2 } from './WebfloRootClient2.js';
|
|
|
3
3
|
import { WebfloSubClient } from './WebfloSubClient.js';
|
|
4
4
|
|
|
5
5
|
export function start() {
|
|
6
|
-
const
|
|
7
|
-
const instance =
|
|
6
|
+
const WebfloRootClient = window.navigation ? WebfloRootClient2 : WebfloRootClient1;
|
|
7
|
+
const instance = WebfloRootClient.create(document, this || {});
|
|
8
8
|
instance.initialize();
|
|
9
9
|
WebfloSubClient.defineElement();
|
|
10
10
|
}
|
|
@@ -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(
|
|
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,
|
|
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(
|
|
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,
|
|
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,
|
|
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(
|
|
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);
|