How to use 'cors npm' in JavaScript

Every line of 'cors npm' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
77function setCors({whitelist = [], logger}) {
78 return cors({
79 origin(origin, callback) {
80 if (whitelist.indexOf(origin) !== -1 || !origin) {
81 callback(null, true);
82 } else {
83 logger.warn({origin, whitelist}, 'Rejected by CORS');
84 callback(new Error('Not allowed by CORS'));
85 }
86 },
87 credentials: true,
88 });
89}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

60function setupCORS (api, path) {
61 api.paths[path].options = api.paths[path].options || cors
62}

Related snippets