Skip to content

Commit

Permalink
Merge pull request #242 from beckn/feat/add-beckn-json
Browse files Browse the repository at this point in the history
Added: Static File For Beckn.json
  • Loading branch information
shreyvishal authored Oct 28, 2024
2 parents 2876882 + 8519a87 commit 83117a7
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cors from "cors";
import { Exception } from "./models/exception.model";
import {
BecknErrorDataType,
BecknErrorType,
BecknErrorType
} from "./schemas/becknError.schema";
import { LookupCache } from "./utils/cache/lookup.cache.utils";
import { RequestCache } from "./utils/cache/request.cache.utils";
Expand All @@ -13,12 +13,14 @@ import { getConfig } from "./utils/config.utils";
import { GatewayUtils } from "./utils/gateway.utils";
import logger from "./utils/logger.utils";
import { Validator } from "./middlewares/validator";
import express from "express";
import path from "path";

const app = Express();

app.use(
Express.json({
limit: "200kb",
limit: "200kb"
})
);

Expand All @@ -29,9 +31,15 @@ const initializeExpress = async () => {
path: "/process"
})
);
app.get("/status", async (req: Request, res: Response, next: NextFunction) => {
res.status(200).send('Added logic to cache OpenAPI validator spec on app load new');
});
app.use("/public", express.static(path.join(__dirname, "../public")));
app.get(
"/status",
async (req: Request, res: Response, next: NextFunction) => {
res
.status(200)
.send("Added logic to cache OpenAPI validator spec on app load new");
}
);

// Enabling Cors
app.options(
Expand All @@ -40,13 +48,13 @@ const initializeExpress = async () => {
origin: "*",
optionsSuccessStatus: 200,
credentials: true,
methods: ["GET", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"],
methods: ["GET", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"]
})
);
app.use(
cors({
origin: "*",
methods: ["GET", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"],
methods: ["GET", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"]
})
);

Expand All @@ -55,10 +63,10 @@ const initializeExpress = async () => {
Express.json({
verify: (req: Request, res: Response, buf: Buffer) => {
res.locals = {
rawBody: buf.toString(),
rawBody: buf.toString()
};
},
limit: "200kb",
limit: "200kb"
})
);

Expand Down Expand Up @@ -88,24 +96,24 @@ const initializeExpress = async () => {
code: err.code,
message: err.message,
data: err.errorData,
type: BecknErrorType.domainError,
type: BecknErrorType.domainError
} as BecknErrorDataType;
res.status(err.code).json({
message: {
ack: {
status: "NACK",
},
status: "NACK"
}
},
error: errorData,
error: errorData
});
} else {
res.status(err.code || 500).json({
message: {
ack: {
status: "NACK",
},
status: "NACK"
}
},
error: err,
error: err
});
}
});
Expand All @@ -131,11 +139,11 @@ const main = async () => {
logger.info("Mode: " + getConfig().app.mode.toLocaleUpperCase());
logger.info(
"Gateway Type: " +
getConfig().app.gateway.mode.toLocaleUpperCase().substring(0, 1) +
getConfig().app.gateway.mode.toLocaleUpperCase().substring(1)
getConfig().app.gateway.mode.toLocaleUpperCase().substring(0, 1) +
getConfig().app.gateway.mode.toLocaleUpperCase().substring(1)
);
await Validator.getInstance().initialize();
logger.info('Initialized openapi validator middleware');
logger.info("Initialized openapi validator middleware");
} catch (err) {
if (err instanceof Exception) {
logger.error(err.toString());
Expand Down

0 comments on commit 83117a7

Please sign in to comment.