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 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 Node.js <code>http.METHODS</code></p>
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 = ['GET', 'PUT', 'DELETE', 'POST', 'PATCH', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT']
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
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "A deterministic server-side for developing and testing frontend clients",
4
4
  "type": "module",
5
- "version": "8.11.1",
5
+ "version": "8.11.2",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "license": "MIT",
package/src/Filename.js CHANGED
@@ -1,4 +1,4 @@
1
- const httpMethods = [ // node:http.METHODS
1
+ const httpMethods = [ // @KeepSync with node:http.METHODS
2
2
  'ACL', 'BIND', 'CHECKOUT',
3
3
  'CONNECT', 'COPY', 'DELETE',
4
4
  'GET', 'HEAD', 'LINK',
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 { StandardMethods } from './utils/http-request.js'
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: StandardMethods,
31
+ corsMethods: SUPPORTED_METHODS,
32
32
  corsHeaders: ['content-type'],
33
33
  corsExposedHeaders: [],
34
34
  corsCredentials: true,
@@ -1,9 +1,7 @@
1
- import { StandardMethods } from './http-request.js'
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
- && StandardMethods.includes(req.headers[CH.AccessControlRequestMethod])
38
+ && methodIsSupported(req.headers[CH.AccessControlRequestMethod])
42
39
  }
43
40
 
44
41
 
@@ -1,7 +1,8 @@
1
- export const StandardMethods = [
2
- 'GET', 'PUT', 'DELETE', 'POST', 'PATCH',
3
- 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT'
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