corsHandler
function corsHandler(allowedOrigins: string = "*", config: Object = {})
Middleware to handle Cross-Origin Resource Sharing (CORS).
Returns: function
- Express middleware function to handle CORS requests.
PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
---|---|---|---|---|
allowedOrigins | string | ✔️ | "*" | Comma-separated list of allowed origins or "*" for all origins. |
config | Object | ✔️ | Additional configuration options for CORS (excluding origin ).See the official CORS package documentation for more details: |
See:
const express = require("express");
const app = express();
app.use(corsHandler("https://example.com,https://another.com", { optionsSuccessStatus: 200 }));
app.get("/", (req, res) => {
res.json({ message: "CORS enabled" });
});