1.2.1 • Published 10 months ago

@chubbyts/chubbyts-cors v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

chubbyts-cors

CI Coverage Status Infection MSI npm-version

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

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

Installation

Through NPM as @chubbyts/chubbyts-cors.

npm i @chubbyts/chubbyts-cors@^1.2.1

Usage

import { createCorsMiddleware } from '@chubbyts/chubbyts-cors/dist/middleware';
import {
  createAllowOriginRegex,
  createHeadersNegotiator,
  createMethodNegotiator,
  createOriginNegotiator,
} from '@chubbyts/chubbyts-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([Method.GET, Method.POST, Method.PUT, Method.DELETE]),
  createHeadersNegotiator(['Content-Type', 'Accept']),
);

(async () => {
  const response = await corsMiddleware(request, handler);
})();

Copyright

2023 Dominik Zogg

1.2.0

10 months ago

1.1.1

10 months ago

1.2.1

10 months ago

1.1.0

1 year ago

1.0.4

1 year ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago