@webqit/webflo 1.0.21 → 1.0.23
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
|
@@ -49,7 +49,7 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
49
49
|
#cx;
|
|
50
50
|
#servers = new Map;
|
|
51
51
|
#proxies = new Map;
|
|
52
|
-
#
|
|
52
|
+
#capabilitiesSetup;
|
|
53
53
|
|
|
54
54
|
// Typically for access by Router
|
|
55
55
|
get cx() { return this.#cx; }
|
|
@@ -102,46 +102,6 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
102
102
|
}));
|
|
103
103
|
}
|
|
104
104
|
// ---------------
|
|
105
|
-
if (this.#cx.server.capabilities?.database) {
|
|
106
|
-
if (this.#cx.server.capabilities.database_dialect !== 'postgres') {
|
|
107
|
-
throw new Error(`Only postgres supported for now for database dialect`);
|
|
108
|
-
}
|
|
109
|
-
if (this.#cx.env.entries[this.#cx.server.capabilities.database_url_variable]) {
|
|
110
|
-
const { SQLClient } = await import('@linked-db/linked-ql/sql');
|
|
111
|
-
const { default: pg } = await import('pg');
|
|
112
|
-
// Obtain pg client
|
|
113
|
-
const pgClient = new pg.Pool({
|
|
114
|
-
connectionString: this.#cx.env.entries[this.#cx.server.capabilities.database_url_variable],
|
|
115
|
-
database: 'postgres',
|
|
116
|
-
});
|
|
117
|
-
// Connect
|
|
118
|
-
await pgClient.connect();
|
|
119
|
-
this.#sdk.db = new SQLClient(pgClient, { dialect: 'postgres' });
|
|
120
|
-
} else {
|
|
121
|
-
//const { ODBClient } = await import('@linked-db/linked-ql/odb');
|
|
122
|
-
//this.#sdk.db = new ODBClient({ dialect: 'postgres' });
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (this.#cx.server.capabilities?.redis && this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable]) {
|
|
126
|
-
const { Redis } = await import('ioredis');
|
|
127
|
-
this.#sdk.redis = !this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable]
|
|
128
|
-
? new Redis : new Redis(this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable], {
|
|
129
|
-
tls: { rejectUnauthorized: false }, // Required for Upstash
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
if (this.#cx.server.capabilities?.webpush) {
|
|
133
|
-
const { default: webpush } = await import('web-push');
|
|
134
|
-
this.#sdk.webpush = webpush;
|
|
135
|
-
if (this.#cx.env.entries[this.#cx.server.capabilities.vapid_public_key_variable]
|
|
136
|
-
&& this.#cx.env.entries[this.#cx.server.capabilities.vapid_private_key_variable]) {
|
|
137
|
-
webpush.setVapidDetails(
|
|
138
|
-
this.#cx.server.capabilities.vapid_subject,
|
|
139
|
-
this.#cx.env.entries[this.#cx.server.capabilities.vapid_public_key_variable],
|
|
140
|
-
this.#cx.env.entries[this.#cx.server.capabilities.vapid_private_key_variable]
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
// ---------------
|
|
145
105
|
this.control();
|
|
146
106
|
if (this.#cx.logger) {
|
|
147
107
|
if (this.#servers.size) {
|
|
@@ -215,12 +175,61 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
215
175
|
const wss = new WebSocket.Server({ noServer: true });
|
|
216
176
|
}
|
|
217
177
|
|
|
178
|
+
async setupCapabilities() {
|
|
179
|
+
if (this.#capabilitiesSetup) return;
|
|
180
|
+
this.#capabilitiesSetup = true;
|
|
181
|
+
if (this.#cx.server.capabilities?.database) {
|
|
182
|
+
if (this.#cx.server.capabilities.database_dialect !== 'postgres') {
|
|
183
|
+
throw new Error(`Only postgres supported for now for database dialect`);
|
|
184
|
+
}
|
|
185
|
+
if (this.#cx.env.entries[this.#cx.server.capabilities.database_url_variable]) {
|
|
186
|
+
console.log('Database capabilities');
|
|
187
|
+
const { SQLClient } = await import('@linked-db/linked-ql/sql');
|
|
188
|
+
const { default: pg } = await import('pg');
|
|
189
|
+
// Obtain pg client
|
|
190
|
+
const pgClient = new pg.Pool({
|
|
191
|
+
connectionString: this.#cx.env.entries[this.#cx.server.capabilities.database_url_variable],
|
|
192
|
+
database: 'postgres',
|
|
193
|
+
});
|
|
194
|
+
// Connect
|
|
195
|
+
await pgClient.connect();
|
|
196
|
+
this.#sdk.db = new SQLClient(pgClient, { dialect: 'postgres' });
|
|
197
|
+
} else {
|
|
198
|
+
console.log('No database capabilities');
|
|
199
|
+
//const { ODBClient } = await import('@linked-db/linked-ql/odb');
|
|
200
|
+
//this.#sdk.db = new ODBClient({ dialect: 'postgres' });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (this.#cx.server.capabilities?.redis && this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable]) {
|
|
204
|
+
const { Redis } = await import('ioredis');
|
|
205
|
+
this.#sdk.redis = !this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable]
|
|
206
|
+
? new Redis : new Redis(this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable], {
|
|
207
|
+
tls: { rejectUnauthorized: false }, // Required for Upstash
|
|
208
|
+
});
|
|
209
|
+
console.log('Redis capabilities');
|
|
210
|
+
}
|
|
211
|
+
if (this.#cx.server.capabilities?.webpush) {
|
|
212
|
+
const { default: webpush } = await import('web-push');
|
|
213
|
+
console.log('Webpuah capabilities');
|
|
214
|
+
this.#sdk.webpush = webpush;
|
|
215
|
+
if (this.#cx.env.entries[this.#cx.server.capabilities.vapid_public_key_variable]
|
|
216
|
+
&& this.#cx.env.entries[this.#cx.server.capabilities.vapid_private_key_variable]) {
|
|
217
|
+
webpush.setVapidDetails(
|
|
218
|
+
this.#cx.server.capabilities.vapid_subject,
|
|
219
|
+
this.#cx.env.entries[this.#cx.server.capabilities.vapid_public_key_variable],
|
|
220
|
+
this.#cx.env.entries[this.#cx.server.capabilities.vapid_private_key_variable]
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
218
226
|
getRequestProto(nodeRequest) {
|
|
219
227
|
return nodeRequest.connection.encrypted ? 'https' : (nodeRequest.headers['x-forwarded-proto'] || 'http');
|
|
220
228
|
}
|
|
221
229
|
|
|
222
230
|
#globalMessagingRegistry = new Map;
|
|
223
231
|
async handleNodeWsRequest(wss, nodeRequest, socket, head) {
|
|
232
|
+
await this.setupCapabilities();
|
|
224
233
|
const proto = this.getRequestProto(nodeRequest).replace('http', 'ws');
|
|
225
234
|
const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest, false);
|
|
226
235
|
const scope = {};
|
|
@@ -281,6 +290,7 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
281
290
|
}
|
|
282
291
|
|
|
283
292
|
async handleNodeHttpRequest(nodeRequest, nodeResponse) {
|
|
293
|
+
await this.setupCapabilities();
|
|
284
294
|
const proto = this.getRequestProto(nodeRequest);
|
|
285
295
|
const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest);
|
|
286
296
|
const scope = {};
|