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
|
- name: media-store-xsuaa
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
parameters:
|
parameters:
|
||||||
path: ./xs-security.json
|
path: deployers/xs-security.json
|
||||||
service-plan: application
|
service-plan: application
|
||||||
service: xsuaa
|
service: xsuaa
|
||||||
type: org.cloudfoundry.managed-service
|
type: org.cloudfoundry.managed-service
|
||||||
|
|||||||
@@ -2,31 +2,13 @@ const cds = require("@sap/cds");
|
|||||||
const {
|
const {
|
||||||
getDurationInMilliseconds,
|
getDurationInMilliseconds,
|
||||||
getFormattedDateTime,
|
getFormattedDateTime,
|
||||||
|
corsMiddleware,
|
||||||
} = require("./util/helpers");
|
} = require("./util/helpers");
|
||||||
|
|
||||||
// handle bootstrapping events...
|
// handle bootstrapping events...
|
||||||
cds.on("bootstrap", (app) => {
|
cds.on("bootstrap", (app) => {
|
||||||
if (cds.env.env === "development") {
|
if (cds.env.env === "development") {
|
||||||
app.use((req, res, next) => {
|
app.use(corsMiddleware);
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
cds.on("served", async ({ db, messaging, ...servedServices }) => {
|
cds.on("served", async ({ db, messaging, ...servedServices }) => {
|
||||||
|
|||||||
@@ -22,7 +22,29 @@ const getFormattedDateTime = () => {
|
|||||||
return formattedDateTime;
|
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 = {
|
module.exports = {
|
||||||
getFormattedDateTime,
|
getFormattedDateTime,
|
||||||
getDurationInMilliseconds,
|
getDurationInMilliseconds,
|
||||||
|
corsMiddleware,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user