@yrpri/api 9.0.172 → 9.0.174
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/app.d.ts +2 -1
- package/app.js +75 -22
- package/models/index.cjs +3 -0
- package/package.json +1 -1
- package/webSockets.d.ts +2 -2
package/app.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import express from "express";
|
|
2
|
+
import type { Server as HttpServer } from "http";
|
|
2
3
|
import WebSocket, { WebSocketServer } from "ws";
|
|
3
4
|
import { RedisClientType } from "@redis/client";
|
|
4
5
|
import { WebSocketsManager } from "./webSockets.js";
|
|
@@ -49,6 +50,6 @@ export declare class YourPrioritiesApi {
|
|
|
49
50
|
registerUserLogin: (user: any | null, userId: number, loginProvider: string, req: YpRequest, done: () => void) => void;
|
|
50
51
|
setupErrorHandler(): void;
|
|
51
52
|
listen(): Promise<void>;
|
|
52
|
-
setupHttpsServer():
|
|
53
|
+
setupHttpsServer(): Promise<HttpServer>;
|
|
53
54
|
}
|
|
54
55
|
export {};
|
package/app.js
CHANGED
|
@@ -214,43 +214,78 @@ export class YourPrioritiesApi {
|
|
|
214
214
|
});
|
|
215
215
|
}
|
|
216
216
|
};
|
|
217
|
+
log.debug("YourPrioritiesApi constructor");
|
|
217
218
|
this.app = express();
|
|
219
|
+
log.debug("Have setup express app");
|
|
218
220
|
this.port = port || (process.env.PORT ? parseInt(process.env.PORT) : 4242);
|
|
219
221
|
this.wsClients = new Map();
|
|
220
222
|
this.initializeRedis();
|
|
223
|
+
log.debug("Have initialized redis");
|
|
221
224
|
this.addRedisToRequest();
|
|
225
|
+
log.debug("Have added redis to request");
|
|
222
226
|
this.addDirnameToRequest();
|
|
227
|
+
log.debug("Have added dirname to request");
|
|
223
228
|
this.forceHttps();
|
|
229
|
+
log.debug("Have forced https");
|
|
224
230
|
this.initializeMiddlewares();
|
|
231
|
+
log.debug("Have initialized middlewares");
|
|
225
232
|
this.handleShortenedRedirects();
|
|
233
|
+
log.debug("Have handled shortened redirects");
|
|
226
234
|
this.initializeRateLimiting();
|
|
235
|
+
log.debug("Have initialized rate limiting");
|
|
227
236
|
this.setupDomainAndCommunity();
|
|
237
|
+
log.debug("Have setup domain and community");
|
|
228
238
|
this.setupNewWebAppVersionHandling();
|
|
239
|
+
log.debug("Have setup new web app version handling");
|
|
229
240
|
this.setupSitemapRoute();
|
|
241
|
+
log.debug("Have setup sitemap route");
|
|
230
242
|
this.initializePassportStrategies();
|
|
243
|
+
log.debug("Have initialized passport strategies");
|
|
231
244
|
this.addInviteAsAnonMiddleWare();
|
|
245
|
+
log.debug("Have added invite as anon middle ware");
|
|
232
246
|
this.setupStaticFileServing();
|
|
247
|
+
log.debug("Have setup static file serving");
|
|
233
248
|
this.checkAuthForSsoInit();
|
|
249
|
+
log.debug("Have checked auth for sso init");
|
|
234
250
|
this.initializeRoutes();
|
|
251
|
+
log.debug("Have initialized routes");
|
|
235
252
|
this.initializeEsControllers();
|
|
253
|
+
log.debug("Have initialized es controllers");
|
|
236
254
|
}
|
|
237
255
|
async initialize() {
|
|
256
|
+
log.debug("YourPrioritiesApi initialize");
|
|
238
257
|
await this.initializeRedis();
|
|
258
|
+
log.debug("Have initialized redis");
|
|
239
259
|
this.addRedisToRequest();
|
|
260
|
+
log.debug("Have added redis to request");
|
|
240
261
|
this.addDirnameToRequest();
|
|
262
|
+
log.debug("Have added dirname to request");
|
|
241
263
|
this.forceHttps();
|
|
264
|
+
log.debug("Have forced https");
|
|
242
265
|
this.initializeMiddlewares();
|
|
266
|
+
log.debug("Have initialized middlewares");
|
|
243
267
|
this.handleShortenedRedirects();
|
|
268
|
+
log.debug("Have handled shortened redirects");
|
|
244
269
|
this.initializeRateLimiting();
|
|
270
|
+
log.debug("Have initialized rate limiting");
|
|
245
271
|
this.setupDomainAndCommunity();
|
|
272
|
+
log.debug("Have setup domain and community");
|
|
246
273
|
this.setupNewWebAppVersionHandling();
|
|
274
|
+
log.debug("Have setup new web app version handling");
|
|
247
275
|
this.setupSitemapRoute();
|
|
276
|
+
log.debug("Have setup sitemap route");
|
|
248
277
|
this.initializePassportStrategies();
|
|
278
|
+
log.debug("Have initialized passport strategies");
|
|
249
279
|
this.addInviteAsAnonMiddleWare();
|
|
280
|
+
log.debug("Have added invite as anon middle ware");
|
|
250
281
|
this.setupStaticFileServing();
|
|
282
|
+
log.debug("Have setup static file serving");
|
|
251
283
|
this.checkAuthForSsoInit();
|
|
284
|
+
log.debug("Have checked auth for sso init");
|
|
252
285
|
this.initializeRoutes();
|
|
286
|
+
log.debug("Have initialized routes");
|
|
253
287
|
this.initializeEsControllers();
|
|
288
|
+
log.debug("Have initialized es controllers");
|
|
254
289
|
}
|
|
255
290
|
setupNewWebAppVersionHandling() {
|
|
256
291
|
this.app.use((req, res, next) => {
|
|
@@ -892,7 +927,7 @@ export class YourPrioritiesApi {
|
|
|
892
927
|
setupErrorHandler() {
|
|
893
928
|
this.app.use((err, req, res, next) => {
|
|
894
929
|
if (err instanceof auth.UnauthorizedError) {
|
|
895
|
-
log.
|
|
930
|
+
log.debug("UnauthorizedError debug", { user: req.user });
|
|
896
931
|
log.error("User Unauthorized", {
|
|
897
932
|
context: "unauthorizedError",
|
|
898
933
|
user: toJson(req.user),
|
|
@@ -976,28 +1011,46 @@ export class YourPrioritiesApi {
|
|
|
976
1011
|
});
|
|
977
1012
|
}
|
|
978
1013
|
async listen() {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
if (process.env.YOUR_PRIORITIES_LISTEN_HOST) {
|
|
987
|
-
server = this.app.listen(portNumber, process.env.YOUR_PRIORITIES_LISTEN_HOST, () => {
|
|
988
|
-
log.info(`Your Priorities Platform API Server listening on port ${process.env.YOUR_PRIORITIES_LISTEN_HOST}:${this.app.get("port")} on ${process.env.NODE_ENV}`);
|
|
989
|
-
});
|
|
1014
|
+
try {
|
|
1015
|
+
log.info("Starting Your Priorities Platform API Server");
|
|
1016
|
+
const server = await this.setupHttpsServer();
|
|
1017
|
+
log.debug("Server created");
|
|
1018
|
+
this.webSocketsManager = new WebSocketsManager(this.wsClients, this.redisClient, server);
|
|
1019
|
+
log.debug("WebSocketsManager created");
|
|
1020
|
+
await this.webSocketsManager.listen();
|
|
990
1021
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
log.error("Error listening on port", { err });
|
|
995
|
-
}
|
|
996
|
-
log.info("Your Priorities Platform API Server listening on port " +
|
|
997
|
-
server.address().port +
|
|
998
|
-
` on ${process.env.NODE_ENV}`);
|
|
999
|
-
});
|
|
1022
|
+
catch (err) {
|
|
1023
|
+
log.error("Server failed to start", { err: err?.message || err });
|
|
1024
|
+
process.exit(1);
|
|
1000
1025
|
}
|
|
1001
|
-
|
|
1026
|
+
}
|
|
1027
|
+
async setupHttpsServer() {
|
|
1028
|
+
const port = Number(process.env.PORT) || 4242;
|
|
1029
|
+
const host = process.env.YOUR_PRIORITIES_LISTEN_HOST || "0.0.0.0";
|
|
1030
|
+
this.app.set("port", port);
|
|
1031
|
+
return await new Promise((resolve, reject) => {
|
|
1032
|
+
const server = this.app.listen(port, host);
|
|
1033
|
+
const onError = (err) => {
|
|
1034
|
+
server.removeListener("listening", onListening);
|
|
1035
|
+
log.error("HTTP server listen error", {
|
|
1036
|
+
code: err?.code,
|
|
1037
|
+
message: err?.message,
|
|
1038
|
+
host,
|
|
1039
|
+
port,
|
|
1040
|
+
});
|
|
1041
|
+
reject(err);
|
|
1042
|
+
};
|
|
1043
|
+
const onListening = () => {
|
|
1044
|
+
server.removeListener("error", onError);
|
|
1045
|
+
const addr = server.address();
|
|
1046
|
+
const rendered = typeof addr === "string"
|
|
1047
|
+
? addr
|
|
1048
|
+
: `${addr.address}:${addr.port}`;
|
|
1049
|
+
log.info(`Your Priorities Platform API Server listening on ${rendered} (env=${process.env.NODE_ENV})`);
|
|
1050
|
+
resolve(server);
|
|
1051
|
+
};
|
|
1052
|
+
server.once("error", onError);
|
|
1053
|
+
server.once("listening", onListening);
|
|
1054
|
+
});
|
|
1002
1055
|
}
|
|
1003
1056
|
}
|
package/models/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ const operatorsAliases = {
|
|
|
33
33
|
};
|
|
34
34
|
if (process.env.NODE_ENV === "production") {
|
|
35
35
|
if (process.env.DISABLE_PG_SSL) {
|
|
36
|
+
logger_cjs_1.default.debug("Creating Sequelize instance with DISABLE_PG_SSL");
|
|
36
37
|
sequelize = new Sequelize(process.env.DATABASE_URL, {
|
|
37
38
|
dialect: "postgres",
|
|
38
39
|
minifyAliases: true,
|
|
@@ -41,6 +42,7 @@ if (process.env.NODE_ENV === "production") {
|
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
else {
|
|
45
|
+
logger_cjs_1.default.debug("Creating Sequelize instance with ENABLE_PG_SSL");
|
|
44
46
|
sequelize = new Sequelize(process.env.DATABASE_URL, {
|
|
45
47
|
dialect: "postgres",
|
|
46
48
|
dialectOptions: { ssl: { rejectUnauthorized: false } },
|
|
@@ -52,6 +54,7 @@ if (process.env.NODE_ENV === "production") {
|
|
|
52
54
|
}
|
|
53
55
|
else {
|
|
54
56
|
try {
|
|
57
|
+
logger_cjs_1.default.debug("Creating Sequelize instance with YP_DEV_DATABASE_NAME");
|
|
55
58
|
sequelize = new Sequelize(process.env.YP_DEV_DATABASE_NAME, process.env.YP_DEV_DATABASE_USERNAME, process.env.YP_DEV_DATABASE_PASSWORD, {
|
|
56
59
|
dialect: "postgres",
|
|
57
60
|
protocol: "postgres",
|
package/package.json
CHANGED
package/webSockets.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Server } from "
|
|
1
|
+
import { Server as HttpServer } from "http";
|
|
2
2
|
import { RedisClientType } from "@redis/client";
|
|
3
3
|
import { WebSocketServer, WebSocket } from "ws";
|
|
4
4
|
/**
|
|
@@ -12,7 +12,7 @@ export declare class WebSocketsManager {
|
|
|
12
12
|
ws: WebSocketServer;
|
|
13
13
|
redisClient: RedisClientType;
|
|
14
14
|
private pingInterval;
|
|
15
|
-
constructor(wsClients: Map<string, WebSocket>, redisClient: RedisClientType, server:
|
|
15
|
+
constructor(wsClients: Map<string, WebSocket>, redisClient: RedisClientType, server: HttpServer);
|
|
16
16
|
/**
|
|
17
17
|
* Main entry point to start listening for connections
|
|
18
18
|
* and initialize Redis pub/sub, heartbeat, etc.
|