Skip to content

docs: update pre-flight cors example according to v5 #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,22 @@ app.listen(80, function () {

You can also enable pre-flight across-the-board like so:

For express v4,
```javascript
app.options('*', cors()) // include before other routes
```

For express v5,
```javascript
// Catch every non-root path
app.options('/*splat', cors());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most users, if not all, the root path is needed, so I think we should remove this.

Suggested change
app.options('/*splat', cors());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example covering root path is also there if you read the next one or two line and both cases are clearly indicated with comments.


// —or—

// Catch everything, including '/'
app.options('/{*splat}', cors());
```

NOTE: When using this middleware as an application level middleware (for
example, `app.use(cors())`), pre-flight requests are already handled for all
routes.
Expand Down
Loading