@jitar-plugins/http
v0.1.5
Published
This package provides plugins for integrating the HTTP protocol in Jitar applications.
Keywords
Readme
HTTP | Jitar Plugins
This package provides plugins for integrating the HTTP protocol in Jitar applications.
It contains two types of middleware:
- CORS - configures cross-origin requests.
- Origin - stores the origin in a cookie to ensure availability across requests.
Both can be used independently.
Installation
npm install @jitar-plugins/httpUsage
Follow the following steps to configure and use the middleware.
Step 1 - Configure the middleware
CORS
// src/middleware/corsMiddleware.ts
import { CorsMiddleware } from '@jitar-plugins/http';
const origin = '*'; // allowed origins (optional, default: *)
const headers = '*'; // allowed headers (optional, default: *)
export default new CorsMiddleware(origin, headers);Origin
// src/middleware/originMiddleware.ts
import { OriginMiddleware } from '@jitar-plugins/http';
const options = {
path: '/rpc', // the path the cookie is valid for (optional, default: '/')
sameSite: 'Strict' | 'Lax' | 'None', // the SameSite attribute of the cookie (optional, default: 'Strict')
secure: true // the Secure attribute of the cookie (optional, default: true)
};
export default new OriginMiddleware(options);Step 2 - Activate the middleware
With the middleware in place, it needs to be activated by registering it to the proxy / standalone / worker service.
/* services/proxy.json */
{
"url": "http://example.com:3000",
"middleware": [ /* add middleware here */
"./middleware/corsMiddleware",
"./middleware/originMiddleware"
],
"proxy":
{
/* service configuration */
}
}