{"id":13716310,"url":"https://github.com/possibilities/micro-cors","last_synced_at":"2025-04-04T08:09:06.715Z","repository":{"id":48022424,"uuid":"78932504","full_name":"possibilities/micro-cors","owner":"possibilities","description":"Simple CORS middleware for Zeit's Micro","archived":false,"fork":false,"pushed_at":"2022-12-07T08:59:12.000Z","size":575,"stargazers_count":195,"open_issues_count":13,"forks_count":32,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T07:09:04.664Z","etag":null,"topics":[],"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/possibilities.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":"2017-01-14T09:56:45.000Z","updated_at":"2024-06-25T07:33:10.000Z","dependencies_parsed_at":"2023-01-24T15:31:05.758Z","dependency_job_id":null,"html_url":"https://github.com/possibilities/micro-cors","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/possibilities%2Fmicro-cors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/possibilities%2Fmicro-cors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/possibilities%2Fmicro-cors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/possibilities%2Fmicro-cors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/possibilities","download_url":"https://codeload.github.com/possibilities/micro-cors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142070,"owners_count":20890652,"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":[],"created_at":"2024-08-03T00:01:09.232Z","updated_at":"2025-04-04T08:09:06.697Z","avatar_url":"https://github.com/possibilities.png","language":"JavaScript","funding_links":[],"categories":["Modules"],"sub_categories":["Middlewares"],"readme":"# CORS middleware for Micro\n\n### Summary\n\nSimple [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) middleware for Zeit's [Micro](https://github.com/zeit/micro)\n\n[![CircleCI](https://circleci.com/gh/possibilities/micro-cors.svg?style=svg)](https://circleci.com/gh/possibilities/micro-cors)\n\n###### We're working on [`v1`](https://github.com/possibilities/micro-cors/issues/51), come help us out!\n\n### Install\n\n```\nyarn add micro-cors\n```\n\n### Usage\n\nBasic:\n\n```js\nconst { send } = require('micro')\nconst cors = require('micro-cors')()\n\nconst handler = (req, res) =\u003e send(res, 200, 'ok!')\n\nmodule.exports = cors(handler)\n```\n\nWith options:\n\n```js\nconst { send } = require('micro')\nconst microCors = require('micro-cors')\nconst cors = microCors({ allowMethods: ['PUT', 'POST'] })\n\nconst handler = (req, res) =\u003e send(res, 200, 'ok!')\n\nmodule.exports = cors(handler)\n```\n\nSince the current version of `micro-cors` only sets headers in the response (`res`), you have do some manual work if you want to avoid triggering your handler on an `OPTIONS` preflight request (this will be built-in in v1). Let's say you want to approve preflight requests and otherwise only let POST requests trigger the handler:\n\n```js\nconst { send } = require('micro')\nconst cors = require('micro-cors')()\n\nconst handler = (req, res) =\u003e {\n  if (req.method === 'OPTIONS') {\n    return send(res, 200, 'ok!');\n  }\n\n  if (req.method !== 'POST') {\n    throw createError(404, 'Not Found');\n  }\n\n  // handle incoming request as usual\n}\n\nmodule.exports = cors(handler)\n```\n\n#### Options\n\n##### `allowMethods`\n\ndefault: `['POST','GET','PUT','PATCH','DELETE','OPTIONS']`\n\n##### `allowHeaders`\n\ndefault: `['X-Requested-With','Access-Control-Allow-Origin','X-HTTP-Method-Override','Content-Type','Authorization','Accept']`\n\n##### `allowCredentials`\n\ndefault: `true`\n\n##### `exposeHeaders`\n\ndefault: `[]`\n\n##### `maxAge`\n\ndefault: `86400`\n\n##### `origin`\n\ndefault: `*`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpossibilities%2Fmicro-cors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpossibilities%2Fmicro-cors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpossibilities%2Fmicro-cors/lists"}