@jaypie/express 1.1.5 → 1.1.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/dist/module.cjs +5 -7
- package/dist/module.esm.js +5 -7
- package/package.json +2 -2
- package/src/cors.helper.js +5 -6
package/dist/module.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var errors = require('@jaypie/errors');
|
|
4
|
-
var expressCors = require('cors');
|
|
5
4
|
var core = require('@jaypie/core');
|
|
5
|
+
var expressCors = require('cors');
|
|
6
6
|
var serverlessExpress = require('@codegenie/serverless-express');
|
|
7
7
|
|
|
8
8
|
//
|
|
@@ -69,7 +69,10 @@ const corsHelper = (config = {}) => {
|
|
|
69
69
|
];
|
|
70
70
|
|
|
71
71
|
// Add localhost origins in sandbox
|
|
72
|
-
if (
|
|
72
|
+
if (
|
|
73
|
+
process.env.PROJECT_ENV === SANDBOX_ENV ||
|
|
74
|
+
core.envBoolean("PROJECT_DEV")
|
|
75
|
+
) {
|
|
73
76
|
allowedOrigins.push("http://localhost");
|
|
74
77
|
allowedOrigins.push(/^http:\/\/localhost:\d+$/);
|
|
75
78
|
}
|
|
@@ -100,20 +103,15 @@ const corsHelper = (config = {}) => {
|
|
|
100
103
|
// Export
|
|
101
104
|
//
|
|
102
105
|
|
|
103
|
-
console.log("Export cors middleware");
|
|
104
106
|
var cors_helper = (config) => {
|
|
105
|
-
console.log("Create cors middleware");
|
|
106
107
|
const cors = corsHelper(config);
|
|
107
108
|
return (req, res, next) => {
|
|
108
|
-
console.log("Run cors middleware");
|
|
109
109
|
cors(req, res, (error) => {
|
|
110
110
|
if (error) {
|
|
111
111
|
res.status(error.status);
|
|
112
112
|
res.setHeader("Content-Type", "application/json");
|
|
113
|
-
console.log("Return cors error");
|
|
114
113
|
return res.json(error.body());
|
|
115
114
|
}
|
|
116
|
-
console.log("Allow next");
|
|
117
115
|
next();
|
|
118
116
|
});
|
|
119
117
|
};
|
package/dist/module.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CorsError } from '@jaypie/errors';
|
|
2
|
+
import { envBoolean, log, JAYPIE, HTTP, validate, force, jaypieHandler, UnhandledError, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, MethodNotAllowedError, GoneError, TeapotError, InternalError, BadGatewayError, UnavailableError, GatewayTimeoutError, NotImplementedError } from '@jaypie/core';
|
|
2
3
|
import expressCors from 'cors';
|
|
3
|
-
import { log, JAYPIE, HTTP, validate, force, jaypieHandler, UnhandledError, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, MethodNotAllowedError, GoneError, TeapotError, InternalError, BadGatewayError, UnavailableError, GatewayTimeoutError, NotImplementedError } from '@jaypie/core';
|
|
4
4
|
import { getCurrentInvoke } from '@codegenie/serverless-express';
|
|
5
5
|
|
|
6
6
|
//
|
|
@@ -67,7 +67,10 @@ const corsHelper = (config = {}) => {
|
|
|
67
67
|
];
|
|
68
68
|
|
|
69
69
|
// Add localhost origins in sandbox
|
|
70
|
-
if (
|
|
70
|
+
if (
|
|
71
|
+
process.env.PROJECT_ENV === SANDBOX_ENV ||
|
|
72
|
+
envBoolean("PROJECT_DEV")
|
|
73
|
+
) {
|
|
71
74
|
allowedOrigins.push("http://localhost");
|
|
72
75
|
allowedOrigins.push(/^http:\/\/localhost:\d+$/);
|
|
73
76
|
}
|
|
@@ -98,20 +101,15 @@ const corsHelper = (config = {}) => {
|
|
|
98
101
|
// Export
|
|
99
102
|
//
|
|
100
103
|
|
|
101
|
-
console.log("Export cors middleware");
|
|
102
104
|
var cors_helper = (config) => {
|
|
103
|
-
console.log("Create cors middleware");
|
|
104
105
|
const cors = corsHelper(config);
|
|
105
106
|
return (req, res, next) => {
|
|
106
|
-
console.log("Run cors middleware");
|
|
107
107
|
cors(req, res, (error) => {
|
|
108
108
|
if (error) {
|
|
109
109
|
res.status(error.status);
|
|
110
110
|
res.setHeader("Content-Type", "application/json");
|
|
111
|
-
console.log("Return cors error");
|
|
112
111
|
return res.json(error.body());
|
|
113
112
|
}
|
|
114
|
-
console.log("Allow next");
|
|
115
113
|
next();
|
|
116
114
|
});
|
|
117
115
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaypie/express",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Finlayson Studio",
|
|
6
6
|
"type": "module",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "b6172271a5bfdc96126fe3eded3e17e382c4409b"
|
|
47
47
|
}
|
package/src/cors.helper.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CorsError } from "@jaypie/errors";
|
|
2
|
+
import { envBoolean } from "@jaypie/core";
|
|
2
3
|
import expressCors from "cors";
|
|
3
4
|
|
|
4
5
|
//
|
|
@@ -52,7 +53,10 @@ const corsHelper = (config = {}) => {
|
|
|
52
53
|
];
|
|
53
54
|
|
|
54
55
|
// Add localhost origins in sandbox
|
|
55
|
-
if (
|
|
56
|
+
if (
|
|
57
|
+
process.env.PROJECT_ENV === SANDBOX_ENV ||
|
|
58
|
+
envBoolean("PROJECT_DEV")
|
|
59
|
+
) {
|
|
56
60
|
allowedOrigins.push("http://localhost");
|
|
57
61
|
allowedOrigins.push(/^http:\/\/localhost:\d+$/);
|
|
58
62
|
}
|
|
@@ -83,20 +87,15 @@ const corsHelper = (config = {}) => {
|
|
|
83
87
|
// Export
|
|
84
88
|
//
|
|
85
89
|
|
|
86
|
-
console.log("Export cors middleware");
|
|
87
90
|
export default (config) => {
|
|
88
|
-
console.log("Create cors middleware");
|
|
89
91
|
const cors = corsHelper(config);
|
|
90
92
|
return (req, res, next) => {
|
|
91
|
-
console.log("Run cors middleware");
|
|
92
93
|
cors(req, res, (error) => {
|
|
93
94
|
if (error) {
|
|
94
95
|
res.status(error.status);
|
|
95
96
|
res.setHeader("Content-Type", "application/json");
|
|
96
|
-
console.log("Return cors error");
|
|
97
97
|
return res.json(error.body());
|
|
98
98
|
}
|
|
99
|
-
console.log("Allow next");
|
|
100
99
|
next();
|
|
101
100
|
});
|
|
102
101
|
};
|