@webqit/webflo 1.0.22 → 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,53 +102,6 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
102
102
|
}));
|
|
103
103
|
}
|
|
104
104
|
// ---------------
|
|
105
|
-
const setupCapabilities = async () => {
|
|
106
|
-
if (this.#cx.server.capabilities?.database) {
|
|
107
|
-
if (this.#cx.server.capabilities.database_dialect !== 'postgres') {
|
|
108
|
-
throw new Error(`Only postgres supported for now for database dialect`);
|
|
109
|
-
}
|
|
110
|
-
if (this.#cx.env.entries[this.#cx.server.capabilities.database_url_variable]) {
|
|
111
|
-
console.log('Database capabilities');
|
|
112
|
-
const { SQLClient } = await import('@linked-db/linked-ql/sql');
|
|
113
|
-
const { default: pg } = await import('pg');
|
|
114
|
-
// Obtain pg client
|
|
115
|
-
const pgClient = new pg.Pool({
|
|
116
|
-
connectionString: this.#cx.env.entries[this.#cx.server.capabilities.database_url_variable],
|
|
117
|
-
database: 'postgres',
|
|
118
|
-
});
|
|
119
|
-
// Connect
|
|
120
|
-
await pgClient.connect();
|
|
121
|
-
this.#sdk.db = new SQLClient(pgClient, { dialect: 'postgres' });
|
|
122
|
-
} else {
|
|
123
|
-
console.log('No database capabilities');
|
|
124
|
-
//const { ODBClient } = await import('@linked-db/linked-ql/odb');
|
|
125
|
-
//this.#sdk.db = new ODBClient({ dialect: 'postgres' });
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (this.#cx.server.capabilities?.redis && this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable]) {
|
|
129
|
-
const { Redis } = await import('ioredis');
|
|
130
|
-
this.#sdk.redis = !this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable]
|
|
131
|
-
? new Redis : new Redis(this.#cx.env.entries[this.#cx.server.capabilities.redis_url_variable], {
|
|
132
|
-
tls: { rejectUnauthorized: false }, // Required for Upstash
|
|
133
|
-
});
|
|
134
|
-
console.log('Redis capabilities');
|
|
135
|
-
}
|
|
136
|
-
if (this.#cx.server.capabilities?.webpush) {
|
|
137
|
-
const { default: webpush } = await import('web-push');
|
|
138
|
-
console.log('Webpuah capabilities');
|
|
139
|
-
this.#sdk.webpush = webpush;
|
|
140
|
-
if (this.#cx.env.entries[this.#cx.server.capabilities.vapid_public_key_variable]
|
|
141
|
-
&& this.#cx.env.entries[this.#cx.server.capabilities.vapid_private_key_variable]) {
|
|
142
|
-
webpush.setVapidDetails(
|
|
143
|
-
this.#cx.server.capabilities.vapid_subject,
|
|
144
|
-
this.#cx.env.entries[this.#cx.server.capabilities.vapid_public_key_variable],
|
|
145
|
-
this.#cx.env.entries[this.#cx.server.capabilities.vapid_private_key_variable]
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
this.#capabilitiesPromise = setupCapabilities();
|
|
151
|
-
// ---------------
|
|
152
105
|
this.control();
|
|
153
106
|
if (this.#cx.logger) {
|
|
154
107
|
if (this.#servers.size) {
|
|
@@ -222,13 +175,61 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
222
175
|
const wss = new WebSocket.Server({ noServer: true });
|
|
223
176
|
}
|
|
224
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
|
+
|
|
225
226
|
getRequestProto(nodeRequest) {
|
|
226
227
|
return nodeRequest.connection.encrypted ? 'https' : (nodeRequest.headers['x-forwarded-proto'] || 'http');
|
|
227
228
|
}
|
|
228
229
|
|
|
229
230
|
#globalMessagingRegistry = new Map;
|
|
230
231
|
async handleNodeWsRequest(wss, nodeRequest, socket, head) {
|
|
231
|
-
await this
|
|
232
|
+
await this.setupCapabilities();
|
|
232
233
|
const proto = this.getRequestProto(nodeRequest).replace('http', 'ws');
|
|
233
234
|
const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest, false);
|
|
234
235
|
const scope = {};
|
|
@@ -289,7 +290,7 @@ export class WebfloServer extends WebfloRuntime {
|
|
|
289
290
|
}
|
|
290
291
|
|
|
291
292
|
async handleNodeHttpRequest(nodeRequest, nodeResponse) {
|
|
292
|
-
await this
|
|
293
|
+
await this.setupCapabilities();
|
|
293
294
|
const proto = this.getRequestProto(nodeRequest);
|
|
294
295
|
const [fullUrl, requestInit] = this.parseNodeRequest(proto, nodeRequest);
|
|
295
296
|
const scope = {};
|