mockaton 8.11.1 → 8.11.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 +2 -2
- package/package.json +1 -1
- package/src/Filename.js +1 -1
- package/src/config.js +2 -2
- package/src/utils/http-cors.js +3 -6
- package/src/utils/http-request.js +5 -4
package/README.md
CHANGED
|
@@ -226,7 +226,7 @@ want a `Content-Type` header in the response.
|
|
|
226
226
|
|
|
227
227
|
<details>
|
|
228
228
|
<summary>Supported Methods</summary>
|
|
229
|
-
<p>From
|
|
229
|
+
<p>From <code>require('node:http').METHODS</code></p>
|
|
230
230
|
<p>
|
|
231
231
|
ACL, BIND, CHECKOUT,
|
|
232
232
|
CONNECT, COPY, DELETE,
|
|
@@ -473,7 +473,7 @@ function capitalizePlugin(filePath) {
|
|
|
473
473
|
Defaults to `true`. When `true`, these are the default options:
|
|
474
474
|
```js
|
|
475
475
|
config.corsOrigins = ['*']
|
|
476
|
-
config.corsMethods =
|
|
476
|
+
config.corsMethods = require('node:http').METHODS
|
|
477
477
|
config.corsHeaders = ['content-type']
|
|
478
478
|
config.corsCredentials = true
|
|
479
479
|
config.corsMaxAge = 0 // seconds to cache the preflight req
|
package/package.json
CHANGED
package/src/Filename.js
CHANGED
package/src/config.js
CHANGED
|
@@ -2,7 +2,7 @@ import { realpathSync } from 'node:fs'
|
|
|
2
2
|
import { isDirectory } from './utils/fs.js'
|
|
3
3
|
import { openInBrowser } from './utils/openInBrowser.js'
|
|
4
4
|
import { jsToJsonPlugin } from './MockDispatcherPlugins.js'
|
|
5
|
-
import {
|
|
5
|
+
import { SUPPORTED_METHODS } from './utils/http-request.js'
|
|
6
6
|
import { validateCorsAllowedMethods, validateCorsAllowedOrigins } from './utils/http-cors.js'
|
|
7
7
|
|
|
8
8
|
|
|
@@ -28,7 +28,7 @@ export const config = Object.seal({
|
|
|
28
28
|
|
|
29
29
|
corsAllowed: true,
|
|
30
30
|
corsOrigins: ['*'],
|
|
31
|
-
corsMethods:
|
|
31
|
+
corsMethods: SUPPORTED_METHODS,
|
|
32
32
|
corsHeaders: ['content-type'],
|
|
33
33
|
corsExposedHeaders: [],
|
|
34
34
|
corsCredentials: true,
|
package/src/utils/http-cors.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { methodIsSupported } from './http-request.js'
|
|
3
2
|
|
|
4
3
|
/* https://www.w3.org/TR/2020/SPSD-cors-20200602/#resource-processing-model */
|
|
5
4
|
|
|
6
|
-
|
|
7
5
|
export function validateCorsAllowedOrigins(arr) {
|
|
8
6
|
if (!Array.isArray(arr))
|
|
9
7
|
return false
|
|
@@ -13,8 +11,7 @@ export function validateCorsAllowedOrigins(arr) {
|
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
export function validateCorsAllowedMethods(arr) {
|
|
16
|
-
return Array.isArray(arr)
|
|
17
|
-
&& arr.every(m => StandardMethods.includes(m))
|
|
14
|
+
return Array.isArray(arr) && arr.every(methodIsSupported)
|
|
18
15
|
}
|
|
19
16
|
|
|
20
17
|
|
|
@@ -38,7 +35,7 @@ const CH = CorsHeader
|
|
|
38
35
|
export function isPreflight(req) {
|
|
39
36
|
return req.method === 'OPTIONS'
|
|
40
37
|
&& URL.canParse(req.headers[CH.Origin])
|
|
41
|
-
&&
|
|
38
|
+
&& methodIsSupported(req.headers[CH.AccessControlRequestMethod])
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { METHODS } from 'node:http'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const SUPPORTED_METHODS = METHODS
|
|
5
|
+
export const methodIsSupported = method => SUPPORTED_METHODS.includes(method)
|
|
5
6
|
|
|
6
7
|
export class BodyReaderError extends Error {name = 'BodyReaderError'}
|
|
7
8
|
|