@appwarden/middleware 3.4.1 → 3.4.2
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/README.md +1 -1
- package/chunk-24CQJ54X.js +11 -0
- package/cloudflare/astro.js +5 -2
- package/cloudflare/react-router.js +5 -2
- package/cloudflare/tanstack-start.js +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://github.com/appwarden/middleware)
|
|
5
5
|
[](https://www.npmjs.com/package/@appwarden/middleware)
|
|
6
6
|
[](https://docs.npmjs.com/generating-provenance-statements)
|
|
7
|
-

|
|
8
8
|
[](https://opensource.org/licenses/MIT)
|
|
9
9
|
|
|
10
10
|
## Core Features
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/utils/is-response-like.ts
|
|
2
|
+
var isResponseLike = (value) => {
|
|
3
|
+
if (!value || typeof value !== "object") return false;
|
|
4
|
+
const candidate = value;
|
|
5
|
+
const headers = candidate.headers;
|
|
6
|
+
return !!(headers && typeof headers === "object" && typeof headers.has === "function" && typeof headers.set === "function" && typeof headers.get === "function" && "body" in candidate);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
isResponseLike
|
|
11
|
+
};
|
package/cloudflare/astro.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isResponseLike
|
|
3
|
+
} from "../chunk-24CQJ54X.js";
|
|
1
4
|
import {
|
|
2
5
|
useContentSecurityPolicy
|
|
3
6
|
} from "../chunk-AXWJZE7U.js";
|
|
@@ -96,7 +99,7 @@ function createAppwardenMiddleware(configFn) {
|
|
|
96
99
|
}
|
|
97
100
|
debugFn("Website is unlocked");
|
|
98
101
|
const response = await next();
|
|
99
|
-
if (config.contentSecurityPolicy) {
|
|
102
|
+
if (config.contentSecurityPolicy && isResponseLike(response)) {
|
|
100
103
|
debugFn("Applying CSP middleware");
|
|
101
104
|
const cspContext = {
|
|
102
105
|
request,
|
|
@@ -119,7 +122,7 @@ function createAppwardenMiddleware(configFn) {
|
|
|
119
122
|
debugFn(`Middleware executed in ${elapsed}ms`);
|
|
120
123
|
return response;
|
|
121
124
|
} catch (error) {
|
|
122
|
-
if (error
|
|
125
|
+
if (isResponseLike(error)) {
|
|
123
126
|
throw error;
|
|
124
127
|
}
|
|
125
128
|
console.error(
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isResponseLike
|
|
3
|
+
} from "../chunk-24CQJ54X.js";
|
|
1
4
|
import {
|
|
2
5
|
useContentSecurityPolicy
|
|
3
6
|
} from "../chunk-AXWJZE7U.js";
|
|
@@ -106,7 +109,7 @@ function createAppwardenMiddleware(configFn) {
|
|
|
106
109
|
}
|
|
107
110
|
debugFn("Website is unlocked");
|
|
108
111
|
const response = await next();
|
|
109
|
-
if (config.contentSecurityPolicy && response
|
|
112
|
+
if (config.contentSecurityPolicy && isResponseLike(response)) {
|
|
110
113
|
debugFn("Applying CSP middleware");
|
|
111
114
|
const cspContext = {
|
|
112
115
|
request,
|
|
@@ -129,7 +132,7 @@ function createAppwardenMiddleware(configFn) {
|
|
|
129
132
|
debugFn(`Middleware executed in ${elapsed}ms`);
|
|
130
133
|
return response;
|
|
131
134
|
} catch (error) {
|
|
132
|
-
if (error
|
|
135
|
+
if (isResponseLike(error)) {
|
|
133
136
|
throw error;
|
|
134
137
|
}
|
|
135
138
|
console.error(
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isResponseLike
|
|
3
|
+
} from "../chunk-24CQJ54X.js";
|
|
1
4
|
import {
|
|
2
5
|
useContentSecurityPolicy
|
|
3
6
|
} from "../chunk-AXWJZE7U.js";
|
|
@@ -91,7 +94,7 @@ function createAppwardenMiddleware(configFn) {
|
|
|
91
94
|
}
|
|
92
95
|
debugFn("Website is unlocked");
|
|
93
96
|
const response = await next();
|
|
94
|
-
if (config.contentSecurityPolicy && response
|
|
97
|
+
if (config.contentSecurityPolicy && isResponseLike(response)) {
|
|
95
98
|
debugFn("Applying CSP middleware");
|
|
96
99
|
const cspContext = {
|
|
97
100
|
request,
|
|
@@ -114,7 +117,7 @@ function createAppwardenMiddleware(configFn) {
|
|
|
114
117
|
debugFn(`Middleware executed in ${elapsed}ms`);
|
|
115
118
|
return response;
|
|
116
119
|
} catch (error) {
|
|
117
|
-
if (error
|
|
120
|
+
if (isResponseLike(error)) {
|
|
118
121
|
throw error;
|
|
119
122
|
}
|
|
120
123
|
console.error(
|