nextjs-cors 2.1.2 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020-present Yony Calsin
3
+ Copyright (c) 2025-present Yony
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,72 +1,44 @@
1
- # Nextjs Cors
1
+ # nextjs-cors
2
2
 
3
- `Nextjs-Cors` is a node.js package to provide a middleware that can be used to enable CORS with various options in nextjs applications.
3
+ CORS middleware for Next.js API routes.
4
4
 
5
5
  [![CI](https://github.com/yonycalsin/nextjs-cors/actions/workflows/ci.yml/badge.svg)](https://github.com/yonycalsin/nextjs-cors/actions/workflows/ci.yml)
6
- <a href="https://github.com/yonycalsin/nextjs-cors"><img src="https://img.shields.io/spiget/stars/1000?color=brightgreen&label=Star&logo=github" /></a>
7
- <a href="https://www.npmjs.com/nextjs-cors" target="_blank">
8
- <img src="https://img.shields.io/npm/v/nextjs-cors" alt="NPM Version" /></a>
9
- <a href="https://www.npmjs.com/nextjs-cors" target="_blank">
10
- <img src="https://img.shields.io/npm/l/nextjs-cors" alt="Package License" /></a>
11
- <a href="https://www.npmjs.com/nextjs-cors" target="_blank">
12
- <img src="https://img.shields.io/npm/dm/nextjs-cors" alt="NPM Downloads" /></a>
13
- <a href="https://github.com/yonycalsin/nextjs-cors"><img src="https://img.shields.io/badge/Github%20Page-nextjs.cors-yellow?style=flat-square&logo=github" /></a>
14
- <a href="https://github.com/yonycalsin"><img src="https://img.shields.io/badge/Author-Yony%20Calsin-blueviolet?style=flat-square&logo=appveyor" /></a>
15
- <a href="https://twitter.com/yonycalsin" target="_blank">
16
- <img src="https://img.shields.io/twitter/follow/yonycalsin.svg?style=social&label=Follow"></a>
6
+ [![npm version](https://img.shields.io/npm/v/nextjs-cors)](https://www.npmjs.com/package/nextjs-cors)
7
+ [![npm downloads](https://img.shields.io/npm/dm/nextjs-cors)](https://www.npmjs.com/package/nextjs-cors)
8
+ [![license](https://img.shields.io/npm/l/nextjs-cors)](LICENSE)
17
9
 
18
10
  ## Installation
19
11
 
20
- > First we will have to install, in order to use this wonderful package.
21
-
22
12
  ```bash
23
- # Using npm
24
- npm install --save nextjs-cors@latest
25
-
26
- # Using yarn
27
- yarn add nextjs-cors@latest
28
-
29
- # Using pnpm
30
- pnpm add nextjs-cors@latest
13
+ npm install nextjs-cors
14
+ # or
15
+ yarn add nextjs-cors
16
+ # or
17
+ pnpm add nextjs-cors
31
18
  ```
32
19
 
33
20
  ## Usage
34
21
 
35
- nextjs-cors uses the cors package, so we invite you to check the documentation https://github.com/expressjs/cors
36
-
37
- > pages/api/whoami.{ts,js}
38
-
39
22
  ```ts
40
- import NextCors from 'nextjs-cors';
41
-
42
- async function handler(req, res) {
43
- // Run the cors middleware
44
- // nextjs-cors uses the cors package, so we invite you to check the documentation https://github.com/expressjs/cors
45
- await NextCors(req, res, {
46
- // Options
47
- methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
48
- origin: '*',
49
- optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
50
- });
51
-
52
- // Rest of the API logic
53
- res.json({ message: 'Hello NextJs Cors!' });
23
+ import NextCors from "nextjs-cors";
24
+
25
+ export default async function handler(req, res) {
26
+ // Run CORS middleware
27
+ await NextCors(req, res, {
28
+ methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
29
+ origin: "*",
30
+ optionsSuccessStatus: 200,
31
+ });
32
+
33
+ // Your API logic
34
+ res.json({ message: "Hello NextJs Cors!" });
54
35
  }
55
36
  ```
56
37
 
57
- ## Support for
58
-
59
- `nextjs-cors` is an open source project licensed by [MIT](LICENSE). You can grow thanks to the sponsors and the support of the amazing sponsors. If you want to join them, [contact me here](https://twitter.com/yonycalsin).
60
-
61
- ## Stay in touch
62
-
63
- - Github [@yonycalsin](https://github.com/yonycalsin)
64
- - Twitter [@yonycalsin](https://twitter.com/yonycalsin)
65
-
66
- ## Contributors
38
+ ## Options
67
39
 
68
- Thanks to the wonderful people who collaborate with me !
40
+ This package uses the [cors](https://github.com/expressjs/cors) package. See the [cors documentation](https://github.com/expressjs/cors#configuration-options) for all available options.
69
41
 
70
42
  ## License
71
43
 
72
- `nextjs-cors` under [License.](LICENSE)
44
+ [MIT](LICENSE)
@@ -0,0 +1,13 @@
1
+ import { CorsOptions, CorsOptionsDelegate } from 'cors';
2
+ import { NextApiRequest, NextApiResponse } from 'next';
3
+
4
+ /**
5
+ * CORS middleware for Next.js API routes
6
+ * @param req - Next.js API request object
7
+ * @param res - Next.js API response object
8
+ * @param options - CORS configuration options (see https://github.com/expressjs/cors#configuration-options)
9
+ * @returns Promise that resolves when CORS middleware completes
10
+ */
11
+ declare function NextCors(req: NextApiRequest, res: NextApiResponse, options?: CorsOptions | CorsOptionsDelegate): Promise<void>;
12
+
13
+ export { NextCors as default };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,13 @@
1
- import cors from 'cors';
2
- import { NextApiRequest, NextApiResponse } from 'next';
3
- declare const NextCors: (req: NextApiRequest, res: NextApiResponse, options?: cors.CorsOptions | cors.CorsOptionsDelegate<cors.CorsRequest> | undefined) => Promise<unknown>;
4
- export default NextCors;
1
+ import { CorsOptions, CorsOptionsDelegate } from 'cors';
2
+ import { NextApiRequest, NextApiResponse } from 'next';
3
+
4
+ /**
5
+ * CORS middleware for Next.js API routes
6
+ * @param req - Next.js API request object
7
+ * @param res - Next.js API response object
8
+ * @param options - CORS configuration options (see https://github.com/expressjs/cors#configuration-options)
9
+ * @returns Promise that resolves when CORS middleware completes
10
+ */
11
+ declare function NextCors(req: NextApiRequest, res: NextApiResponse, options?: CorsOptions | CorsOptionsDelegate): Promise<void>;
12
+
13
+ export { NextCors as default };
package/dist/index.js CHANGED
@@ -1,8 +1,21 @@
1
+ 'use strict';
1
2
 
2
- 'use strict'
3
+ var cors = require('cors');
3
4
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./nextjs-cors.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./nextjs-cors.cjs.development.js')
5
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
+
7
+ var cors__default = /*#__PURE__*/_interopDefault(cors);
8
+
9
+ // src/index.ts
10
+ function NextCors(req, res, options) {
11
+ return new Promise((resolve, reject) => {
12
+ cors__default.default(options)(req, res, (result) => {
13
+ if (result instanceof Error) {
14
+ return reject(result);
15
+ }
16
+ resolve();
17
+ });
18
+ });
8
19
  }
20
+
21
+ module.exports = NextCors;
package/dist/index.mjs ADDED
@@ -0,0 +1,15 @@
1
+ import cors from 'cors';
2
+
3
+ // src/index.ts
4
+ function NextCors(req, res, options) {
5
+ return new Promise((resolve, reject) => {
6
+ cors(options)(req, res, (result) => {
7
+ if (result instanceof Error) {
8
+ return reject(result);
9
+ }
10
+ resolve();
11
+ });
12
+ });
13
+ }
14
+
15
+ export { NextCors as default };
package/package.json CHANGED
@@ -1,15 +1,12 @@
1
1
  {
2
2
  "name": "nextjs-cors",
3
- "version": "2.1.2",
4
- "private": false,
3
+ "version": "2.2.1",
5
4
  "description": "Nextjs-Cors is a node.js package to provide a middleware that can be used to enable CORS with various options in nextjs applications.",
6
5
  "keywords": [
7
6
  "nextjs-cors",
8
- "express-cors",
9
- "nextjs-express-cors",
10
7
  "next-cors",
11
- "cors-server",
12
- "cors"
8
+ "cors",
9
+ "nextjs"
13
10
  ],
14
11
  "homepage": "https://github.com/yonycalsin/nextjs-cors#readme",
15
12
  "bugs": {
@@ -20,86 +17,43 @@
20
17
  "url": "git+https://github.com/yonycalsin/nextjs-cors.git"
21
18
  },
22
19
  "license": "MIT",
23
- "author": "Yony Calsin",
20
+ "author": "Yony",
24
21
  "main": "dist/index.js",
25
- "module": "dist/nextjs-cors.esm.js",
26
- "typings": "dist/index.d.ts",
22
+ "module": "dist/index.mjs",
23
+ "types": "dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "require": "./dist/index.js",
28
+ "import": "./dist/index.mjs"
29
+ }
30
+ },
27
31
  "files": [
28
32
  "dist",
29
- "package.json",
30
33
  "README.md"
31
34
  ],
32
35
  "scripts": {
33
- "clean": "rimraf dist",
34
- "boot": "npm run clean && npm run build",
35
- "typecheck": "tsc --noEmit",
36
- "start": "tsdx watch",
37
- "build": "tsdx build",
38
- "test": "tsdx test",
39
- "lint": "tsdx lint",
40
- "prepare": "tsdx build",
41
- "prettier": "prettier --ignore-path .gitignore \"**/*.{ts,tsx,json,md}\"",
42
- "format": "npm run prettier -- --write",
43
- "check-format": "npm run prettier -- --list-different",
44
- "semantic-release": "semantic-release"
45
- },
46
- "husky": {
47
- "hooks": {
48
- "pre-commit": "tsdx lint",
49
- "pre-push": "npm run typecheck"
50
- }
51
- },
52
- "lint-staged": {
53
- "*.{ts,js}": [
54
- "eslint --fix"
55
- ]
36
+ "build": "tsup",
37
+ "prepublishOnly": "npm run build",
38
+ "changeset": "changeset",
39
+ "version": "changeset version",
40
+ "release": "npm run build && changeset publish"
56
41
  },
57
42
  "dependencies": {
58
43
  "cors": "^2.8.5"
59
44
  },
60
45
  "devDependencies": {
61
- "@semantic-release/changelog": "^6.0.1",
62
- "@semantic-release/git": "^10.0.1",
63
- "@types/cors": "^2.8.12",
64
- "husky": "^6.0.0",
65
- "lint-staged": "^10.5.4",
66
- "next": "^11.1.0",
67
- "prettier": "^2.0.5",
68
- "prettier-plugin-organize-imports": "^2.0.0",
69
- "prettier-plugin-packagejson": "^2.2.5",
70
- "rimraf": "^3.0.2",
71
- "semantic-release": "^19.0.5",
72
- "tsdx": "^0.14.1",
73
- "typescript": "^4.4.2"
46
+ "@changesets/changelog-github": "^0.5.1",
47
+ "@changesets/cli": "^2.29.7",
48
+ "@types/cors": "^2.8.17",
49
+ "next": "^15.0.0",
50
+ "tsup": "^8.5.0",
51
+ "typescript": "^5.6.0"
74
52
  },
75
53
  "peerDependencies": {
76
- "next": "^8.1.1-canary.54 || ^9.0.0 || ^10.0.0-0 || ^11.0.0 || ^12.0.0 || ^13.0.0"
54
+ "next": ">=8.1.1-canary.54"
77
55
  },
78
56
  "publishConfig": {
79
57
  "access": "public"
80
- },
81
- "release": {
82
- "branches": [
83
- "master"
84
- ],
85
- "plugins": [
86
- "@semantic-release/commit-analyzer",
87
- "@semantic-release/release-notes-generator",
88
- "@semantic-release/npm",
89
- [
90
- "@semantic-release/github",
91
- {
92
- "assets": [
93
- "dist/**",
94
- "package.json",
95
- "README.md"
96
- ]
97
- }
98
- ],
99
- "@semantic-release/changelog"
100
- ]
101
- },
102
- "volta": {
103
- "node": "14.17.0"
104
58
  }
105
59
  }
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var cors = _interopDefault(require('cors'));
8
-
9
- // And to throw an error when an error happens in a middleware
10
-
11
- function initMiddleware(middleware) {
12
- return function (req, res, options) {
13
- return new Promise(function (resolve, reject) {
14
- middleware(options)(req, res, function (result) {
15
- if (result instanceof Error) {
16
- return reject(result);
17
- }
18
-
19
- return resolve(result);
20
- });
21
- });
22
- };
23
- } // You can read more about the available options here: https://github.com/expressjs/cors#configuration-options
24
-
25
-
26
- var NextCors = /*#__PURE__*/initMiddleware(cors);
27
-
28
- exports.default = NextCors;
29
- //# sourceMappingURL=nextjs-cors.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nextjs-cors.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["import cors, { CorsOptions, CorsOptionsDelegate } from 'cors'\nimport { NextApiRequest, NextApiResponse } from 'next'\n\n// Helper method to wait for a middleware to execute before continuing\n// And to throw an error when an error happens in a middleware\nfunction initMiddleware(middleware: typeof cors) {\n return (req: NextApiRequest, res: NextApiResponse, options?: CorsOptions | CorsOptionsDelegate) =>\n new Promise((resolve, reject) => {\n middleware(options)(req, res, (result: Error | unknown) => {\n if (result instanceof Error) {\n return reject(result)\n }\n\n return resolve(result)\n })\n })\n}\n\n// You can read more about the available options here: https://github.com/expressjs/cors#configuration-options\nconst NextCors = initMiddleware(cors)\n\nexport default NextCors\n"],"names":["initMiddleware","middleware","req","res","options","Promise","resolve","reject","result","Error","NextCors","cors"],"mappings":";;;;;;;;AAIA;;AACA,SAASA,cAAT,CAAwBC,UAAxB;AACE,SAAO,UAACC,GAAD,EAAsBC,GAAtB,EAA4CC,OAA5C;AAAA,WACL,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV;AACVN,MAAAA,UAAU,CAACG,OAAD,CAAV,CAAoBF,GAApB,EAAyBC,GAAzB,EAA8B,UAACK,MAAD;AAC5B,YAAIA,MAAM,YAAYC,KAAtB,EAA6B;AAC3B,iBAAOF,MAAM,CAACC,MAAD,CAAb;AACD;;AAED,eAAOF,OAAO,CAACE,MAAD,CAAd;AACD,OAND;AAOD,KARD,CADK;AAAA,GAAP;AAUD;;;AAGD,IAAME,QAAQ,gBAAGV,cAAc,CAACW,IAAD,CAA/B;;;;"}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=(e=require("cors"))&&"object"==typeof e&&"default"in e?e.default:e;function t(e){return function(r,t,n){return new Promise((function(o,u){e(n)(r,t,(function(e){return e instanceof Error?u(e):o(e)}))}))}}exports.default=t(r);
2
- //# sourceMappingURL=nextjs-cors.cjs.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nextjs-cors.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["import cors, { CorsOptions, CorsOptionsDelegate } from 'cors'\nimport { NextApiRequest, NextApiResponse } from 'next'\n\n// Helper method to wait for a middleware to execute before continuing\n// And to throw an error when an error happens in a middleware\nfunction initMiddleware(middleware: typeof cors) {\n return (req: NextApiRequest, res: NextApiResponse, options?: CorsOptions | CorsOptionsDelegate) =>\n new Promise((resolve, reject) => {\n middleware(options)(req, res, (result: Error | unknown) => {\n if (result instanceof Error) {\n return reject(result)\n }\n\n return resolve(result)\n })\n })\n}\n\n// You can read more about the available options here: https://github.com/expressjs/cors#configuration-options\nconst NextCors = initMiddleware(cors)\n\nexport default NextCors\n"],"names":["initMiddleware","middleware","req","res","options","Promise","resolve","reject","result","Error","cors"],"mappings":"+IAKA,SAASA,EAAeC,UACf,SAACC,EAAqBC,EAAsBC,UACjD,IAAIC,SAAQ,SAACC,EAASC,GACpBN,EAAWG,EAAXH,CAAoBC,EAAKC,GAAK,SAACK,UACzBA,aAAkBC,MACbF,EAAOC,GAGTF,EAAQE,0BAMNR,EAAeU"}
@@ -1,23 +0,0 @@
1
- import cors from 'cors';
2
-
3
- // And to throw an error when an error happens in a middleware
4
-
5
- function initMiddleware(middleware) {
6
- return function (req, res, options) {
7
- return new Promise(function (resolve, reject) {
8
- middleware(options)(req, res, function (result) {
9
- if (result instanceof Error) {
10
- return reject(result);
11
- }
12
-
13
- return resolve(result);
14
- });
15
- });
16
- };
17
- } // You can read more about the available options here: https://github.com/expressjs/cors#configuration-options
18
-
19
-
20
- var NextCors = /*#__PURE__*/initMiddleware(cors);
21
-
22
- export default NextCors;
23
- //# sourceMappingURL=nextjs-cors.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nextjs-cors.esm.js","sources":["../src/index.ts"],"sourcesContent":["import cors, { CorsOptions, CorsOptionsDelegate } from 'cors'\nimport { NextApiRequest, NextApiResponse } from 'next'\n\n// Helper method to wait for a middleware to execute before continuing\n// And to throw an error when an error happens in a middleware\nfunction initMiddleware(middleware: typeof cors) {\n return (req: NextApiRequest, res: NextApiResponse, options?: CorsOptions | CorsOptionsDelegate) =>\n new Promise((resolve, reject) => {\n middleware(options)(req, res, (result: Error | unknown) => {\n if (result instanceof Error) {\n return reject(result)\n }\n\n return resolve(result)\n })\n })\n}\n\n// You can read more about the available options here: https://github.com/expressjs/cors#configuration-options\nconst NextCors = initMiddleware(cors)\n\nexport default NextCors\n"],"names":["initMiddleware","middleware","req","res","options","Promise","resolve","reject","result","Error","NextCors","cors"],"mappings":";;AAIA;;AACA,SAASA,cAAT,CAAwBC,UAAxB;AACE,SAAO,UAACC,GAAD,EAAsBC,GAAtB,EAA4CC,OAA5C;AAAA,WACL,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV;AACVN,MAAAA,UAAU,CAACG,OAAD,CAAV,CAAoBF,GAApB,EAAyBC,GAAzB,EAA8B,UAACK,MAAD;AAC5B,YAAIA,MAAM,YAAYC,KAAtB,EAA6B;AAC3B,iBAAOF,MAAM,CAACC,MAAD,CAAb;AACD;;AAED,eAAOF,OAAO,CAACE,MAAD,CAAd;AACD,OAND;AAOD,KARD,CADK;AAAA,GAAP;AAUD;;;AAGD,IAAME,QAAQ,gBAAGV,cAAc,CAACW,IAAD,CAA/B;;;;"}