{"id":15014110,"url":"https://github.com/sankalpafernando/cors-extends","last_synced_at":"2026-03-14T18:13:09.174Z","repository":{"id":57209578,"uuid":"467883627","full_name":"SankalpaFernando/cors-extends","owner":"SankalpaFernando","description":null,"archived":false,"fork":false,"pushed_at":"2022-03-09T10:39:58.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-21T23:49:26.228Z","etag":null,"topics":["cors","cors-proxy","express","jest","npm-package","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/cors-extends","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SankalpaFernando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-09T10:39:21.000Z","updated_at":"2024-02-06T00:10:51.000Z","dependencies_parsed_at":"2022-09-01T08:41:00.537Z","dependency_job_id":null,"html_url":"https://github.com/SankalpaFernando/cors-extends","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/SankalpaFernando/cors-extends","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SankalpaFernando%2Fcors-extends","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SankalpaFernando%2Fcors-extends/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SankalpaFernando%2Fcors-extends/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SankalpaFernando%2Fcors-extends/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SankalpaFernando","download_url":"https://codeload.github.com/SankalpaFernando/cors-extends/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SankalpaFernando%2Fcors-extends/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28005983,"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","status":"online","status_checked_at":"2025-12-24T02:00:07.193Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-proxy","express","jest","npm-package","typescript"],"created_at":"2024-09-24T19:45:12.388Z","updated_at":"2025-12-24T18:09:53.552Z","avatar_url":"https://github.com/SankalpaFernando.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cors-Extends\n\nCors-Extend is a package which provides the configuration to the existing [Cors](http://www.senchalabs.org/connect/) nodejs package and which enables to configure cors according to the environments.\n\n# Installation\n\n- [Cors-Extends](#cors-extends)\n- [Installation](#installation)\n\t- [Usage](#usage)\n\t\t- [Simple Usage (define environments \u0026 global configuration)](#simple-usage-define-environments--global-configuration)\n\t- [Configuration By Environment Variable](#configuration-by-environment-variable)\n\t\t- [Configure the Origin](#configure-the-origin)\n\t\t- [Configure the Routes](#configure-the-routes)\n\n```sh\n$ npm install cors-extends\n```\n\n## Usage\n\n### Simple Usage (define environments \u0026 global configuration)\n\n```javascript\nimport cors from \"cors\";\nimport { corsExtends } from \"cors-extend\";\n\ncors(\n\tcorsExtends({\n\t\tenv: {\n\t\t\tdevelopment: {\n\t\t\t\torigins: [\n\t\t\t\t\t{\n\t\t\t\t\t\torigin: \"http://localhost:3000\",\n\t\t\t\t\t\tmethods: [\"GET\"],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\troutes: [\n\t\t\t\t\t{\n\t\t\t\t\t\tendpoint: \"/characters\",\n\t\t\t\t\t\tmethods: [\"GET\", \"POST\"],\n\t\t\t\t\t\torigins: [\"http://localhost:5000\"],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tglobal: {\n\t\t\tblockHttpClient: true,\n\t\t},\n\t}),\n);\n```\n\n## Configuration By Environment Variable\n\nCors-Extend is capable of loading specific configuration according to Environment variable, **ENVIRONMENT**. The variable can be pass either by dotenv cli, .env file or any other way.\n\n`Note` that both environment variable value and configuration name should be equal\\*\n\nAfter configuring environment variable in configuration file under the env object specify the environment name\n\u003cbr\u003e\n\n```javascript\ncors(corsExtends({\n  env{\n    development:{\n\n    }\n  }\n}))\n```\n\nThe endpoints can be configured in two ways\n\u003cbr\u003e\n\n### Configure the Origin\n\nBy using this configuration we can specify the origins and methods that are allowed for that origins, for the entire application.\n\norigins is an array of object which has a template of\n\n```\n{\n  origin:\"Origin Name\",\n  methods:[\"GET\",\"POST\",\"PUT\",\"DELETE\",\"PATCH\"]\n}\n```\n\nExample:\n\n```javascript\nenv: {\n\tdevelopment: {\n\t\torigins: [\n\t\t\t{\n\t\t\t\torigin: \"http://localhost:3000\",\n\t\t\t\tmethods: [\"GET\"],\n\t\t\t},\n\t\t];\n\t}\n}\n```\n\nSo, according to the above configuration the application will only accept **GET** requests from the client **http://localhost:3000**\n\n`Note` When the origins param or configuration for the certain environment is unspecified, all the requests from all origins will be accepted **(Not recommended)**.\n\n### Configure the Routes\n\nRoutes configuration is used to specify the cors configuration for certain routes.\n\nroutes is an array of object which has a template of\n\n| Property | Type | Optional | Description |\n| -------- | ---- | --- |----------- |\n| endpoint | String | false | Specify the **Route** that needs to be configured |\n| methods | String[] | true | Specify the **Methods** that would be allowed to the route |\n| origins | String[] | false | Specify the **Origins** that would be allowed to the route |\n| blockHttpClient | Boolean | true | Specify whether to block requests from **non Browser Clients** |\n\nExample:\n\n```javascript\nenv: {\n\tdevelopment: {\n\t  origins: [\n\t   {\n\t    endpoint: \"/route\",\n\t    methods: [\"GET\",\"POST\"],\n\t    origins: [\n\t\t\"http://localhost:1000\",\n\t\t\"http://web.sankalpafernando\"\n\t    ],\n\t    blockHttpClient: false,\n\t   },\n\t  ];\n\t}\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsankalpafernando%2Fcors-extends","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsankalpafernando%2Fcors-extends","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsankalpafernando%2Fcors-extends/lists"}