Skip to content

Commit

Permalink
Added: Feature For load OpenAPIValidator Cache on app boot
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyvishal committed Jun 18, 2024
1 parent ba9e1a1 commit e29fcda
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
4 changes: 1 addition & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const initializeExpress = async (successCallback: Function) => {

// Error Handler.
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
console.log("In Error Handler---->middleware", err);
console.log(err);
if (err instanceof Exception) {
const errorData = {
code: err.code,
Expand Down Expand Up @@ -117,8 +117,6 @@ const main = async () => {
try {
await ClientUtils.initializeConnection();
await GatewayUtils.getInstance().initialize();

console.log("After Open API middleware");
if (getConfig().responseCache.enabled) {
await ResponseCache.getInstance().initialize();
}
Expand Down
26 changes: 7 additions & 19 deletions src/middlewares/schemaValidator.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ const initializeOpenApiValidatorCache = async (
}

actions.slice(0, 2).forEach((action) => {
console.log("Action is:", action);
const mockRequest = (body: any) => {
const req = httpMocks.createRequest({
method: "POST",
Expand Down Expand Up @@ -204,39 +203,28 @@ const initializeOpenApiValidatorCache = async (
context: { action: `${action}` },
message: {}
});
console.log(`Mock created for action ${action} and domain ${specFile}`);
walkSubstack(
stack,
reqObj,
{},
() => {
return;
},
true
);

walkSubstack(stack, reqObj, {}, () => {
return;
});
});
} catch (error: any) {
console.log(error.message);
}
} catch (error: any) {}
};

const walkSubstack = function (
stack: any,
req: any,
res: any,
next: NextFunction,
showError = true
next: NextFunction
) {
if (typeof stack === "function") {
stack = [stack];
}
const walkStack = function (i: any, err?: any) {
if (err && showError) {
console.log(`Walk Stack Error at ${i}`);
if (err) {
return schemaErrorHandler(err, req, res, next);
}
if (i >= stack.length) {
console.log("Going out of this walkstack");
return next();
}
stack[i](req, res, walkStack.bind(null, i + 1));
Expand Down
4 changes: 1 addition & 3 deletions src/utils/mongo.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export class DBClient {
this.db = this.client.db();
this.isConnected = true;
logger.info(`Mongo Client Connected For DB: ${this.db.databaseName}`);
} catch (error: any) {
console.log(error);
}
} catch (error: any) {}
}

public getDB(): Db {
Expand Down

0 comments on commit e29fcda

Please sign in to comment.