move xs-securiry.json
This commit is contained in:
committed by
Daniel Hutzel
parent
ee63541845
commit
64cc4ec26a
@@ -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
|
||||
|
||||
@@ -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 }) => {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user