@ejfdelgado/ejflab-back 1.32.4 → 1.32.6

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/srv/Network.mjs +20 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-back",
3
- "version": "1.32.4",
3
+ "version": "1.32.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ejfdelgado/ejflab-back.git"
@@ -19,7 +19,7 @@
19
19
  "license": "ISC",
20
20
  "private": false,
21
21
  "dependencies": {
22
- "@ejfdelgado/ejflab-common": "1.16.2",
22
+ "@ejfdelgado/ejflab-common": "1.16.3",
23
23
  "@google-cloud/compute": "^4.7.0",
24
24
  "@google-cloud/firestore": "^7.9.0",
25
25
  "@google-cloud/storage": "^7.11.3",
package/srv/Network.mjs CHANGED
@@ -16,6 +16,25 @@ function stringify(circ) {
16
16
  return text;
17
17
  };
18
18
 
19
+ function corsCustomDomains(allowedOrigins = []) {
20
+ return (req, res, next) => {
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,