rajivharlalka
02/25/2022, 5:22 AMconst initialize = async app => {
server = http.createServer(app);
app.use(bodyParser.urlencoded({extended: true}));
app.use(helmet());
initSupertokens();
app.use(
cors({
origin: function (origin, callback) {
if (config.get("cors.whitelist").indexOf(origin) !== -1 || config.get("cors.allowLocal")) {
// error - null, allowOrigin - true
callback(null, true);
} else {
app.use(function (err, req, res) {
res.status(403).json({
success: false,
statusCode: "NOT_ALLOWED_BY_CORS",
message: "You are not allowed to access this resource",
data: {},
});
});
// error - true, allowOrigin - false
callback(true, false);
}
},
allowedHeaders: ["content-type", ...supertokens.getAllCORSHeaders()],
credentials: true,
})
);
app.use(middleware());
app.get("/health", (req, res) => {
res.status(200).send({PBL: "Up and Running"});
});
app.use(errorHandler());
app.enable("trust proxy");
server.listen(config.api.port);
server.timeout = config.get("server.timeout");
logger.info(`Server started at port ${config.api.port}`);
};
And this init function is called at the start of the App