From d5e92d075e813221e28d97283f41d5eee72165e9 Mon Sep 17 00:00:00 2001 From: Sergo Date: Sun, 30 Jul 2023 10:27:00 +0300 Subject: [PATCH 1/2] adjust index file --- index.ts | 30 ++++++++++++++++++++++----- src/services/aliases/aliases.class.ts | 7 +++++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/index.ts b/index.ts index a203c16..1a1c7eb 100644 --- a/index.ts +++ b/index.ts @@ -3,11 +3,31 @@ import { logger } from "./logger"; const port = app.get("port"); const host = app.get("host"); - -process.on("unhandledRejection", (reason) => - logger.error("Unhandled Rejection %O", reason), -); +const server = app.listen(port); app.listen(port).then(() => { - logger.info(`Feathers app listening on http://${host}:${port}`); + logger.info(`Walias app listening on http://${host}:${port}`); +}); + +process.on("SIGINT", () => { + logger.info("Received SIGINT signal. Shutting down gracefully."); + + server.close(() => { + logger.info("HTTP server closed."); + process.exit(0); + }); +}); + +process.on("SIGTERM", () => { + logger.info("Received SIGTERM signal. Shutting down gracefully."); + + server.close(() => { + logger.info("HTTP server closed."); + process.exit(0); + }); +}); + +process.on("unhandledRejection", (reason) => { + logger.error("Unhandled rejection", reason); + process.exit(1); }); diff --git a/src/services/aliases/aliases.class.ts b/src/services/aliases/aliases.class.ts index e64ab35..af938e3 100644 --- a/src/services/aliases/aliases.class.ts +++ b/src/services/aliases/aliases.class.ts @@ -47,7 +47,7 @@ export interface AliasesParams extends Params { export class AliasesService implements ServiceInterface { - constructor(public options: AliasesServiceOptions) { } + constructor(public options: AliasesServiceOptions) {} async find(params: ServiceParams): Promise { const userId = await this.getUserIdByEmailAddress(params); @@ -117,7 +117,10 @@ export class AliasesService const allowedDomain: string = config.get("wildDuck.domain"); // If address does not match the allowed domain, throw an error - if (!allowedDomain || !addressInfoResponse.address.endsWith(allowedDomain)) { + if ( + !allowedDomain || + !addressInfoResponse.address.endsWith(allowedDomain) + ) { throw new BadRequest("Unable to delete address"); } -- 2.45.2 From f2ded792c51fff41b0727f8833e2dae2bc3d8b60 Mon Sep 17 00:00:00 2001 From: Sergo Date: Fri, 4 Aug 2023 08:42:51 +0300 Subject: [PATCH 2/2] filter emails to search by --- config/default.json | 3 ++- src/services/aliases/aliases.class.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config/default.json b/config/default.json index 5680920..62b451a 100644 --- a/config/default.json +++ b/config/default.json @@ -12,6 +12,7 @@ "wildDuck": { "url": "http://localhost", "token": "aaaaa", - "domain": "test-codemowers.eu" + "domain": "test-codemowers.eu", + "preferredDomain": "k-space.ee" } } \ No newline at end of file diff --git a/src/services/aliases/aliases.class.ts b/src/services/aliases/aliases.class.ts index 59941e1..928ec99 100644 --- a/src/services/aliases/aliases.class.ts +++ b/src/services/aliases/aliases.class.ts @@ -93,7 +93,9 @@ export class AliasesService const emails = params.session?.user?.emails; const addressInfoResponse = await Promise.any( - emails.map((email: string) => + emails + .filter((email: string) => email.endsWith(config.get("wildDuck.preferredDomain"))) + .map((email: string) => wildDuckClient.get(`addresses/resolve/${email}`), ), ); -- 2.45.2