@jitar-plugins/http 0.0.2 → 0.0.3

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
@@ -3,10 +3,12 @@
3
3
 
4
4
  This package provides plugins for integrating the HTTP protocol in Jitar applications.
5
5
 
6
- It contains two middleware:
6
+ It contains two types of middleware:
7
7
 
8
- * **CORS** for handling Cross-Origin Resource Sharing (CORS) requests.
9
- * **Origin** for ensuring the availability of the origin header.
8
+ * **CORS** - configures cross-origin requests.
9
+ * **Origin** - ensures the avaiability of the origin header.
10
+
11
+ Both can be used indenpendently.
10
12
 
11
13
  ## Installation
12
14
 
@@ -16,16 +18,31 @@ npm install @jitar-plugins/http
16
18
 
17
19
  ## Usage
18
20
 
19
- Follow the following steps to configure and use the provided middleware.
21
+ Follow the following steps to configure and use the middleware.
20
22
 
21
23
  ### Step 1 - Configure the middleware
22
24
 
25
+ **CORS**
26
+
27
+ ```ts
28
+ // src/middleware/corsMiddleware.ts
29
+
30
+ import { CorsMiddleware } from '@jitar-plugins/http';
31
+
32
+ const origin = '*'; // allowed orgins (optional, default: *)
33
+ const headers = '*'; // allowed headers (optional, default: *)
34
+
35
+ export default new CorsMiddleware(origin, headers);
36
+ ```
37
+
38
+ **Origin**
39
+
23
40
  ```ts
24
41
  // src/middleware/originMiddleware.ts
25
42
 
26
- import OriginMiddleware from '@jitar-plugins/http';
43
+ import { OriginMiddleware } from '@jitar-plugins/http';
27
44
 
28
- export default new OriginMiddleware();
45
+ export default new OriginMiddleware(); // no configuration options
29
46
  ```
30
47
 
31
48
  ### Step 2 - Activate the middleware
@@ -37,6 +54,7 @@ With the health check in place, it needs to be activated by registering it to th
37
54
  {
38
55
  "url": "http://example.com:3000",
39
56
  "middleware": [ /* add middleware here */
57
+ "./middleware/corsMiddleware",
40
58
  "./middleware/originMiddleware"
41
59
  ],
42
60
  "proxy":
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { default as CorsMiddleware } from './CorsMiddleware';
2
- export { default as OriginMiddleware } from './OriginMiddleware';
1
+ export { default as CorsMiddleware } from './CorsMiddleware.js';
2
+ export { default as OriginMiddleware } from './OriginMiddleware.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { default as CorsMiddleware } from './CorsMiddleware';
2
- export { default as OriginMiddleware } from './OriginMiddleware';
1
+ export { default as CorsMiddleware } from './CorsMiddleware.js';
2
+ export { default as OriginMiddleware } from './OriginMiddleware.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jitar-plugins/http",
3
3
  "private": false,
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsc",
@@ -17,7 +17,7 @@
17
17
  "types": "dist/index.d.ts",
18
18
  "exports": "./dist/index.js",
19
19
  "peerDependencies": {
20
- "@theshelf/validation": "^0.0.2",
20
+ "@theshelf/validation": "^0.0.3",
21
21
  "jitar": "^0.10.3"
22
22
  }
23
23
  }