Files
Matt Godbolt c3ca289a05 Specifically allow OPTIONS for browser preflight CORS checks. (#7596)
Google AI suggested too (independently, I did this first then searched
and got:

---

1. Using Middleware
A middleware function can intercept OPTIONS requests and set the
appropriate CORS headers.

```js
app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS");
  res.header("Access-Control-Allow-Headers", "Content-Type, Authorization");
  if (req.method === 'OPTIONS') {
    res.sendStatus(200);
  } else {
    next();
  }
});
```
---

Tested locally with curl on GET, OPTIONS, and POST and correctly lets
OPTIONS return an empty CORS block, etc. And the site works too :)

---------

Co-authored-by: Mats Jun Larsen <mats@jun.codes>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-04-22 21:29:04 -05:00
..
2024-04-22 20:01:30 +02:00
2025-02-18 10:28:10 -06:00
2025-02-26 11:11:12 -06:00
2025-02-26 02:07:09 +02:00
2025-02-25 13:05:50 -06:00
2025-02-26 10:56:26 -06:00