@ejfdelgado/ejflab-back 1.32.5 → 1.32.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/srv/Network.mjs +21 -1
package/package.json
CHANGED
package/srv/Network.mjs
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import md5 from "md5";
|
2
2
|
import { Buffer } from "buffer";
|
3
3
|
import { MyError } from "./MyError.mjs";
|
4
|
-
import { MyUtilities } from "@ejfdelgado/ejflab-common/src/MyUtilities.js";
|
5
4
|
|
6
5
|
function stringify(circ) {
|
7
6
|
var cache = [];
|
@@ -16,6 +15,26 @@ function stringify(circ) {
|
|
16
15
|
return text;
|
17
16
|
};
|
18
17
|
|
18
|
+
function corsCustomDomains(allowedOrigins = []) {
|
19
|
+
return (req, res, next) => {
|
20
|
+
const origin = req.headers.origin;
|
21
|
+
if (req.method == 'OPTIONS') {
|
22
|
+
if (allowedOrigins.includes(origin)) {
|
23
|
+
res.setHeader('Access-Control-Allow-Origin', origin);
|
24
|
+
}
|
25
|
+
res.setHeader('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE');
|
26
|
+
res.setHeader('Access-Control-Allow-Headers', '*');
|
27
|
+
res.setHeader('Access-Control-Max-Age', '3600');
|
28
|
+
res.status(204).send('');
|
29
|
+
} else {
|
30
|
+
if (allowedOrigins.includes(origin)) {
|
31
|
+
res.setHeader('Access-Control-Allow-Origin', origin);
|
32
|
+
}
|
33
|
+
next();
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
19
38
|
function cors(req, res, next) {
|
20
39
|
if (req.method == 'OPTIONS') {
|
21
40
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
@@ -101,6 +120,7 @@ function handleErrorsDecorator(someFun) {
|
|
101
120
|
|
102
121
|
export {
|
103
122
|
cors,
|
123
|
+
corsCustomDomains,
|
104
124
|
getEnvVariables,
|
105
125
|
urlNorFound,
|
106
126
|
commonHeaders,
|