@chubbyts/chubbyts-undici-cors
v1.0.0
Published
A minimal cors middleware for chubbyts-undici-server.
Downloads
373
Readme
chubbyts-undici-cors
Description
A minimal cors middleware for chubbyts-undici-server.
Requirements
- node: 20
- @chubbyts/chubbyts-undici-server: ^1.0.0
Installation
Through NPM as @chubbyts/chubbyts-undici-cors.
npm i @chubbyts/chubbyts-undici-cors@^1.0.0Usage
import { createCorsMiddleware } from '@chubbyts/chubbyts-undici-cors/dist/middleware';
import {
createAllowOriginRegex,
createHeadersNegotiator,
createMethodNegotiator,
createOriginNegotiator,
} from '@chubbyts/chubbyts-undici-cors/dist/negotiation';
import { Handler, Response, ServerRequest } from '@chubbyts/chubbyts-undici-server/dist/server';
const corsMiddleware = createCorsMiddleware(
createOriginNegotiator([createAllowOriginRegex(/^https?\:\/\/localhost(\:\d+)?$/)]),
createMethodNegotiator(['GET', 'POST', 'PUT', 'DELETE']),
createHeadersNegotiator(['Content-Type', 'Accept']),
);
const handler: Handler = async (serverRequest: ServerRequest) => {
return new Response();
};
(async () => {
const serverRequest = new ServerRequest();
const response = await corsMiddleware(serverRequest, handler);
})();Copyright
2025 Dominik Zogg
