move xs-securiry.json

This commit is contained in:
Dzmitry_Tamashevich@epam.com
2020-11-29 21:32:14 +03:00
committed by Daniel Hutzel
parent ee63541845
commit 64cc4ec26a
4 changed files with 25 additions and 21 deletions

View File

@@ -121,7 +121,7 @@ resources:
- name: media-store-xsuaa
# ------------------------------------------------------------
parameters:
path: ./xs-security.json
path: deployers/xs-security.json
service-plan: application
service: xsuaa
type: org.cloudfoundry.managed-service

View File

@@ -2,31 +2,13 @@ const cds = require("@sap/cds");
const {
getDurationInMilliseconds,
getFormattedDateTime,
corsMiddleware,
} = require("./util/helpers");
// handle bootstrapping events...
cds.on("bootstrap", (app) => {
if (cds.env.env === "development") {
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Methods",
"GET, PUT, PATCH, POST, DELETE, OPTIONS"
);
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization, Accept-Language"
);
//intercepts OPTIONS method
if ("OPTIONS" === req.method) {
//respond with 200
res.sendStatus(200);
} else {
//move on
next();
}
});
app.use(corsMiddleware);
}
});
cds.on("served", async ({ db, messaging, ...servedServices }) => {

View File

@@ -22,7 +22,29 @@ const getFormattedDateTime = () => {
return formattedDateTime;
};
const corsMiddleware = (req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Methods",
"GET, PUT, PATCH, POST, DELETE, OPTIONS"
);
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization, Accept-Language"
);
//intercepts OPTIONS method
if ("OPTIONS" === req.method) {
//respond with 200
res.sendStatus(200);
} else {
//move on
next();
}
};
module.exports = {
getFormattedDateTime,
getDurationInMilliseconds,
corsMiddleware,
};