docs (middleware-cors): Improve readme
MODIFY
packages/middleware-cors/README.md
packages/middleware-cors/README.md
-Middleware Cors
+Middleware CORS
=======
A CORS middleware for [Marble.js](https://github.com/marblejs/marble).
## Usage
-Example of using this middleware on a GET route.
+Example to allow incoming requests.
-```javascript
-import { cors$ } from '@marblejs/middleware-cors';
-
-const foo$ = EffectFactory
- .matchPath('/foo/:id')
- .matchType('GET')
- .use(req$ => req$.pipe(
- use(cors$({
- origin: 'https://foo.bar',
- }));
- // ...
- ));
-```
-
-Example to allow all incoming requests.
-
-```javascript
+```typescript
import { cors$ } from '@marblejs/middleware-cors';
const middlewares = [
@@ -31,9 +15,9 @@ const middlewares = [
cors$({
origin: '*',
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
- withCredentials: false,
optionsSuccessStatus: 204,
allowHeaders: '*',
+ maxAge: 3600,
})
];
@@ -46,4 +30,20 @@ const effects = [
const app = httpListener({ middlewares, effects });
```
+## Available options
+
+To configure CORS middleware you can follow this interface.
+
+```typescript
+interface CORSOptions {
+ origin?: string | string[] | RegExp;
+ methods?: HttpMethod[];
+ optionsSuccessStatus?: HttpStatus;
+ allowHeaders?: string | string[];
+ exposeHeaders?: string[];
+ withCredentials?: boolean;
+ maxAge?: number;
+}
+```
+
License: MIT

docs (middleware-cors): Improve readme