{"id":13776269,"url":"https://github.com/detailyang/lua-resty-cors","last_synced_at":"2026-01-28T08:53:42.391Z","repository":{"id":69113189,"uuid":"70483823","full_name":"detailyang/lua-resty-cors","owner":"detailyang","description":"It's the implement of CORS on OpenResty ","archived":false,"fork":false,"pushed_at":"2018-11-05T12:29:26.000Z","size":21,"stargazers_count":55,"open_issues_count":2,"forks_count":17,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-02-13T21:48:35.609Z","etag":null,"topics":["cors","resty"],"latest_commit_sha":null,"homepage":"","language":"Lua","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/detailyang.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-10-10T12:04:04.000Z","updated_at":"2023-11-16T08:18:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"e8a9cb95-abc6-4645-9956-cf57ebcca0af","html_url":"https://github.com/detailyang/lua-resty-cors","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/detailyang%2Flua-resty-cors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/detailyang%2Flua-resty-cors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/detailyang%2Flua-resty-cors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/detailyang%2Flua-resty-cors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/detailyang","download_url":"https://codeload.github.com/detailyang/lua-resty-cors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253551497,"owners_count":21926304,"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","resty"],"created_at":"2024-08-03T18:00:21.391Z","updated_at":"2026-01-28T08:53:42.356Z","avatar_url":"https://github.com/detailyang.png","language":"Lua","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"Name\n====\nlua-resty-cors\n\n# lua-resty-cors\nIt's the implement of [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) on OpenResty and \nIt backports the [nginx-http-cors](https://github.com/x-v8/ngx_http_cors_filter) to OpenResty\n\nTable of Contents\n-----------------\n* [Name](#name)\n* [Status](#status)\n* [Usage](#usage)\n* [API](#api)\n* [Contributing](#contributing)\n* [Author](#author)\n* [License](#license)\n\n\nStatus\n====\n[![Build Status](https://travis-ci.org/detailyang/lua-resty-cors.svg?branch=master)](https://travis-ci.org/detailyang/lua-resty-cors)\n\nUsage\n====\nIt may be placed on the nginx http block for a global CORS config or in each server block to configure a different CORS for each virtual host as the following:\n\n```bash\n\nhttp {\n      init_by_lua_block {\n        local cors = require('lib.resty.cors');\n\n        cors.allow_host([==[.*\\.google\\.com]==])\n        cors.allow_host([==[.*\\.facebook\\.com]==])\n        cors.expose_header('x-custom-field1')\n        cors.expose_header('x-custom-field2')\n        cors.allow_method('GET')\n        cors.allow_method('POST')\n        cors.allow_method('PUT')\n        cors.allow_method('DELETE')\n        cors.allow_header('x-custom-field1')\n        cors.allow_header('x-custom-field2')\n        cors.max_age(7200)\n        cors.allow_credentials(false)\n      }\n      \n      header_filter_by_lua_block {\n        local cors = require('lib.resty.cors');\n        cors.run()\n    }\n}\n```\n\nAPI\n====\n\nallow_host\n---\n`syntax: cors.allow_host(host)`\n\nThis will match the host from cors request then be added to the header Access-Control-Allow-Origin like as the following:\n\n```bash\nRequest:\nOrigin: https://www.google.com\n\nResponse:\nAccess-Control-Allow-Origin: http://www.google.com\n```\n\nexpose_header\n---\n`syntax: cors.expose_header(header)`\n\nThis will be added to the header Access-Control-Expose-Headers like as the following:\n\n```bash\nRequest:\nOrigin: https://www.google.com\n\nResponse:\nAccess-Control-Expose-Headers: x-custom-field1,x-custom-field2\n```\n\nallow_method\n---\n`syntax: cors.allow_method(method)`\n\nThis will be added to the header Access-Control-Allow-Methods like as the following:\n\n```bash\nRequest:\nOrigin: https://www.google.com\n\nResponse:\nAccess-Control-Allow-Methods:GET,POST,PUT\n```\n\nallow_header\n---\n`syntax: cors.allow_header(header)`\n\nThis will be added to the header Access-Control-Allow-Headers like as the following:\n\n```bash\nRequest:\nOrigin: https://www.google.com\n\nResponse:\nAccess-Control-Allow-Headers:x-custom-field1,x-custom-field2\n```\n\nmax_age\n---\n`syntax: cors.max_age(age)`\n\nThis will be added to the header Access-Control-Max-Age like as the following:\n\n```bash\nRequest:\nOrigin: https://www.google.com\n\nResponse:\nAccess-Control-Max-Age: 7200\n```\n\nAllow-Credentials\n---\n`syntax: cors.allow_credentials(true or false)`\n\nThis will be added to the header Access-Control-Allow-Credentials like as the following:\n\n```bash\nRequest:\nOrigin: https://www.google.com\n\nResponse:\nAccess-Control-Allow-Credentials: true\n```\n\nrun\n---\n`syntax: cors.run()`\n\nThis is the entry for lua-resty-cors to run\n\n\nContributing\n------------\n\nTo contribute to lua-resty-cors, clone this repo locally and commit your code on a separate branch.\n\nPS: PR Welcome :rocket: :rocket: :rocket: :rocket:\n\n\nAuthor\n------\n\n\u003e GitHub [@detailyang](https://github.com/detailyang)\n\nLicense\n-------\nlua-resty-cors is licensed under the [MIT] license.\n\n[MIT]: https://github.com/detailyang/ybw/blob/master/licenses/MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdetailyang%2Flua-resty-cors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdetailyang%2Flua-resty-cors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdetailyang%2Flua-resty-cors/lists"}