1.4.0 • Published 9 months ago
@chubbyts/chubbyts-http-cors v1.4.0
chubbyts-http-cors
Description
A CORS middleware for @chubbyts/chubbyts-http-types.
Apply toLowerCase() to each related request header name before pass the request to this middleware.
Requirements
- node: 18
- @chubbyts/chubbyts-http-types: ^1.3.1 || ^2.0.0
Installation
Through NPM as @chubbyts/chubbyts-http-cors.
npm i @chubbyts/chubbyts-http-cors@^1.4.0Usage
import { createCorsMiddleware } from '@chubbyts/chubbyts-http-cors/dist/middleware';
import {
createAllowOriginRegex,
createHeadersNegotiator,
createMethodNegotiator,
createOriginNegotiator,
} from '@chubbyts/chubbyts-http-cors/dist/negotiation';
import { createResponseFactory } from '@chubbyts/chubbyts-http/dist/message-factory';
import { Method } from '@chubbyts/chubbyts-http-types/dist/message';
const corsMiddleware = createCorsMiddleware(
createResponseFactory(),
createOriginNegotiator([createAllowOriginRegex(/^https?\:\/\/localhost(\:\d+)?$/)]),
createMethodNegotiator(['GET', 'POST', 'PUT', 'DELETE']),
createHeadersNegotiator(['Content-Type', 'Accept']),
);
(async () => {
const response = await corsMiddleware(request, handler);
})();Copyright
2025 Dominik Zogg