3 examples of 'npm install cors' in JavaScript

Every line of 'npm install cors' 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
158function setupCors(swaggerApp, remotes) {
159 var corsOptions = remotes.options && remotes.options.cors ||
160 { origin: true, credentials: true };
161
162 // TODO(bajtos) Skip CORS when remotes.options.cors === false
163 swaggerApp.use(cors(corsOptions));
164}
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

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}
60function setupCORS (api, path) {
61 api.paths[path].options = api.paths[path].options || cors
62}

Related snippets