{"id":23318773,"url":"https://github.com/noderaider/universal-cors","last_synced_at":"2025-04-07T05:19:52.796Z","repository":{"id":57386553,"uuid":"60726755","full_name":"noderaider/universal-cors","owner":"noderaider","description":"CORS middleware implementation with emphasis on configurability of dynamic origins.","archived":false,"fork":false,"pushed_at":"2016-11-04T06:47:58.000Z","size":150,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T12:34:09.755Z","etag":null,"topics":["cors","cors-middleware","dynamic-origins","express","universal-cors"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noderaider.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-08T19:58:54.000Z","updated_at":"2016-06-08T19:59:07.000Z","dependencies_parsed_at":"2022-09-05T14:00:49.508Z","dependency_job_id":null,"html_url":"https://github.com/noderaider/universal-cors","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noderaider%2Funiversal-cors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noderaider%2Funiversal-cors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noderaider%2Funiversal-cors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noderaider%2Funiversal-cors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noderaider","download_url":"https://codeload.github.com/noderaider/universal-cors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595556,"owners_count":20963972,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cors","cors-middleware","dynamic-origins","express","universal-cors"],"created_at":"2024-12-20T17:19:12.773Z","updated_at":"2025-04-07T05:19:52.776Z","avatar_url":"https://github.com/noderaider.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## universal-cors\r\n\r\n**CORS middleware implementation with emphasis on configurability of dynamic origins.**\r\n\r\n[![Build Status](https://travis-ci.org/noderaider/universal-cors.svg?branch=master)](https://travis-ci.org/noderaider/universal-cors)\r\n[![codecov](https://codecov.io/gh/noderaider/universal-cors/branch/master/graph/badge.svg)](https://codecov.io/gh/noderaider/universal-cors)\r\n\r\n[![NPM](https://nodei.co/npm/universal-cors.png?stars=true\u0026downloads=true)](https://nodei.co/npm/universal-cors/)\r\n\r\n\r\n## Install\r\n\r\n`npm i -S universal-cors`\r\n\r\n\r\n## How to use\r\n\r\n\r\n```js\r\nimport express from 'express'\r\nimport cors, { origins } from 'universal-cors'\r\n\r\n\r\nconst app = express()\r\n\r\n/** cors middleware to accept any pattern matching example.com subdomains */\r\napp.use(cors({ patterns: [ /^https:\\/\\/.*\\.example\\.com/ ]}))\r\n\r\n/** ROUTERS GO HERE */\r\n```\r\n\r\n\r\n## Documentation\r\n\r\n**cors default export - middleware for auto handling preflight responses, testing dynamic origins, and attaching cors response headers when valid request occurs**\r\n\r\n```js\r\ncors([opts: Object]): function(req, res, next)\r\n```\r\n\r\n*opts*\r\n\r\n**name**        | **type**                              | **default**   | **description**\r\n--------        | --------                              | -----------   | ---------------\r\n`patterns`      | `string|RegExp|Array\u003cstring|RegExp\u003e`  | **required**  | the pattern(s) to test for cors origins, if pattern matches, the response will get valid cors response headers.\r\n`preflight`     | `function(req): responseHeaders`      | `(req) =\u003e {}` | issues preflight responses for OPTIONS method requests and returns specified headers\r\n`tracing`       | `boolean`                             | `false`       | toggles tracing for debugging purposes\r\n`logger`        | `Object`                              | `console`     | the logger object to trace to\r\n`loglevel`      | `string`                              | `'info'`      | the log level to use when tracing (`error`, `warn`, `info`, `trace`)\r\n\r\n\r\nAn example of what you might set for preflight:\r\n\r\n```js\r\nconst preflight = req =\u003e {\r\n  return  { 'Access-Control-Allow-Origin': req.headers.origin\r\n          , 'Access-Control-Max-Age': 604800 // Specifies how long the preflight response can be cached in seconds\r\n          , 'Access-Control-Allow-Methods': 'GET, PUT, POST, DELETE'\r\n          , 'Access-Control-Allow-Headers': 'Content-Type, Authorization'\r\n          , 'Access-Control-Allow-Credentials': true\r\n          }\r\n}\r\n```\r\n\r\n**origins export - granular origin testing functionality**\r\n\r\n```js\r\norigins([opts: Object]): { isOk: function(domain: string): boolean }\r\n```\r\n\r\n*opts*\r\n\r\n**name**        | **type**                              | **default**   | **description**\r\n--------        | --------                              | -----------   | ---------------\r\n`patterns`      | `string|RegExp|Array\u003cstring|RegExp\u003e`  | **required**  | the pattern(s) to test for cors origins, if pattern matches, the response will get valid cors response headers.\r\n`tracing`       | `boolean`                             | `false`       | toggles tracing for debugging purposes\r\n`logger`        | `Object`                              | `console`     | the logger object to trace to\r\n`loglevel`      | `string`                              | `'info'`      | the log level to use when tracing (`error`, `warn`, `info`, `trace`)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoderaider%2Funiversal-cors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoderaider%2Funiversal-cors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoderaider%2Funiversal-cors/lists"}