Performance: cors middleware setup
MEDIUM IMPACT
This affects the server response time and the browser's ability to load resources from different origins safely.
import cors from 'cors'; const corsOptions = { origin: 'https://example.com', methods: ['GET', 'POST'], optionsSuccessStatus: 204 }; app.use(cors(corsOptions));
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', '*');
next();
});| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Naive CORS allowing all origins with no OPTIONS handling | N/A | N/A | Delays resource loading | [X] Bad |
| Using cors middleware with specific origin and methods | N/A | N/A | Faster resource loading | [OK] Good |