nextjs-cors 1.0.7 → 2.1.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/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Nextjs Cors
2
2
 
3
- `Nextjs-Cors` is a function that allows you to enter an object, by means of points, and very easily, and is compatible with **typescript**
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.
4
4
 
5
+ [![CI](https://github.com/yonycalsin/nextjs-cors/actions/workflows/ci.yml/badge.svg)](https://github.com/yonycalsin/nextjs-cors/actions/workflows/ci.yml)
5
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>
6
7
  <a href="https://www.npmjs.com/nextjs-cors" target="_blank">
7
8
  <img src="https://img.shields.io/npm/v/nextjs-cors" alt="NPM Version" /></a>
@@ -9,14 +10,12 @@
9
10
  <img src="https://img.shields.io/npm/l/nextjs-cors" alt="Package License" /></a>
10
11
  <a href="https://www.npmjs.com/nextjs-cors" target="_blank">
11
12
  <img src="https://img.shields.io/npm/dm/nextjs-cors" alt="NPM Downloads" /></a>
12
- <a href="https://github.com/yonycalsin/nextjs-cors" target="_blank">
13
- <img src="https://s3.amazonaws.com/assets.coveralls.io/badges/coveralls_95.svg" alt="Coverage" /></a>
14
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>
15
14
  <a href="https://github.com/yonycalsin"><img src="https://img.shields.io/badge/Author-Yony%20Calsin-blueviolet?style=flat-square&logo=appveyor" /></a>
16
15
  <a href="https://twitter.com/yonycalsin" target="_blank">
17
16
  <img src="https://img.shields.io/twitter/follow/yonycalsin.svg?style=social&label=Follow"></a>
18
17
 
19
- ## 🍉 Installation
18
+ ## Installation
20
19
 
21
20
  > First we will have to install, in order to use this wonderful package.
22
21
 
@@ -28,7 +27,7 @@ npm install --save nextjs-cors@latest
28
27
  yarn add nextjs-cors@latest
29
28
  ```
30
29
 
31
- ## 🌎 Usage
30
+ ## Usage
32
31
 
33
32
  nextjs-cors uses the cors package, so we invite you to check the documentation https://github.com/expressjs/cors
34
33
 
@@ -52,19 +51,19 @@ async function handler(req, res) {
52
51
  }
53
52
  ```
54
53
 
55
- ## ⭐ Support for
54
+ ## Support for
56
55
 
57
56
  `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).
58
57
 
59
- ## 🎩 Stay in touch
58
+ ## Stay in touch
60
59
 
61
- - Github [@yonycalsin](https://github.com/yonycalsin)
62
- - Twitter [@yonycalsin](https://twitter.com/yonycalsin)
60
+ - Github [@yonycalsin](https://github.com/yonycalsin)
61
+ - Twitter [@yonycalsin](https://twitter.com/yonycalsin)
63
62
 
64
- ## 🚀 Contributors
63
+ ## Contributors
65
64
 
66
65
  Thanks to the wonderful people who collaborate with me !
67
66
 
68
- ## 📜 License
67
+ ## License
69
68
 
70
- `nextjs-cors` under [License MIT.](LICENSE)
69
+ `nextjs-cors` under [License.](LICENSE)
@@ -1,4 +1,4 @@
1
- import { CorsOptions, CorsOptionsDelegate } from 'cors';
1
+ import cors from 'cors';
2
2
  import { NextApiRequest, NextApiResponse } from 'next';
3
- declare const NextCors: (req: NextApiRequest, res: NextApiResponse, options?: CorsOptions | CorsOptionsDelegate) => Promise<unknown>;
3
+ declare const NextCors: (req: NextApiRequest, res: NextApiResponse, options?: cors.CorsOptions | cors.CorsOptionsDelegate<cors.CorsRequest> | undefined) => Promise<unknown>;
4
4
  export default NextCors;
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
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')
8
+ }
@@ -0,0 +1,29 @@
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
@@ -0,0 +1 @@
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;;;;"}
@@ -0,0 +1,2 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,23 @@
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
@@ -0,0 +1 @@
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;;;;"}
package/package.json CHANGED
@@ -1,72 +1,77 @@
1
1
  {
2
- "name": "nextjs-cors",
3
- "version": "1.0.7",
4
- "private": false,
5
- "description": "nextjs-cors is a node.js package to provide a Connect/Express middleware that can be used to enable CORS with various options.",
6
- "keywords": [
7
- "nextjs-cors",
8
- "express-cors",
9
- "nextjs-express-cors",
10
- "next-cors",
11
- "cors-server",
12
- "cors"
13
- ],
14
- "homepage": "https://github.com/yonycalsin/nextjs-cors#readme",
15
- "bugs": {
16
- "url": "https://github.com/yonycalsin/nextjs-cors/issues"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/yonycalsin/nextjs-cors.git"
21
- },
22
- "license": "MIT",
23
- "author": "Yony Calsin",
24
- "main": ".dist/index.js",
25
- "types": ".dist/index.d.ts",
26
- "files": [
27
- ".dist"
28
- ],
29
- "scripts": {
30
- "build": "tsc",
31
- "clean": "rimraf .dist",
32
- "dev": "nodemon",
33
- "format": "prettier --write ./**/*.{ts,json}",
34
- "typecheck": "tsc --noEmit"
35
- },
36
- "husky": {
37
- "hooks": {
38
- "pre-push": "npm run typecheck"
39
- }
40
- },
41
- "lint-staged": {
42
- "*.{ts,js}": [
43
- "eslint --fix"
44
- ]
45
- },
46
- "dependencies": {
47
- "cors": "^2.8.5"
48
- },
49
- "devDependencies": {
50
- "@types/cors": "^2.8.12",
51
- "@types/react": "^17.0.18",
52
- "@types/react-dom": "^17.0.9",
53
- "husky": "^6.0.0",
54
- "lint-staged": "^10.5.4",
55
- "next": "^11.1.0",
56
- "nodemon": "^2.0.4",
57
- "prettier": "^2.0.5",
58
- "prettier-plugin-organize-imports": "^2.0.0",
59
- "prettier-plugin-packagejson": "^2.2.5",
60
- "react": "^17.0.2",
61
- "react-dom": "^17.0.2",
62
- "rimraf": "^3.0.2",
63
- "ts-node": "^10.2.1",
64
- "typescript": "^4.3.5"
65
- },
66
- "peerDependencies": {
67
- "next": "^8.1.1-canary.54 || ^9.0.0 || ^10.0.0 || ^11.0.0"
68
- },
69
- "publishConfig": {
70
- "access": "public"
71
- }
2
+ "name": "nextjs-cors",
3
+ "version": "2.1.1",
4
+ "private": false,
5
+ "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
+ "keywords": [
7
+ "nextjs-cors",
8
+ "express-cors",
9
+ "nextjs-express-cors",
10
+ "next-cors",
11
+ "cors-server",
12
+ "cors"
13
+ ],
14
+ "homepage": "https://github.com/yonycalsin/nextjs-cors#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/yonycalsin/nextjs-cors/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/yonycalsin/nextjs-cors.git"
21
+ },
22
+ "license": "MIT",
23
+ "author": "Yony Calsin",
24
+ "main": "dist/index.js",
25
+ "module": "dist/nextjs-cors.esm.js",
26
+ "typings": "dist/index.d.ts",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "scripts": {
31
+ "clean": "rimraf dist",
32
+ "boot": "npm run clean && npm run build",
33
+ "typecheck": "tsc --noEmit",
34
+ "start": "tsdx watch",
35
+ "build": "tsdx build",
36
+ "test": "tsdx test",
37
+ "lint": "tsdx lint",
38
+ "prepare": "tsdx build",
39
+ "prettier": "prettier --ignore-path .gitignore \"**/*.{ts,tsx,json,md}\"",
40
+ "format": "npm run prettier -- --write",
41
+ "check-format": "npm run prettier -- --list-different",
42
+ "semantic-release": "semantic-release"
43
+ },
44
+ "husky": {
45
+ "hooks": {
46
+ "pre-commit": "tsdx lint",
47
+ "pre-push": "npm run typecheck"
48
+ }
49
+ },
50
+ "lint-staged": {
51
+ "*.{ts,js}": [
52
+ "eslint --fix"
53
+ ]
54
+ },
55
+ "dependencies": {
56
+ "cors": "^2.8.5"
57
+ },
58
+ "devDependencies": {
59
+ "@types/cors": "^2.8.12",
60
+ "husky": "^6.0.0",
61
+ "lint-staged": "^10.5.4",
62
+ "next": "^11.1.0",
63
+ "prettier": "^2.0.5",
64
+ "prettier-plugin-organize-imports": "^2.0.0",
65
+ "prettier-plugin-packagejson": "^2.2.5",
66
+ "rimraf": "^3.0.2",
67
+ "semantic-release": "^18.0.0",
68
+ "tsdx": "^0.14.1",
69
+ "typescript": "^4.4.2"
70
+ },
71
+ "peerDependencies": {
72
+ "next": "^8.1.1-canary.54 || ^9.0.0 || ^10.0.0-0 || ^11.0.0 || ^12.0.0"
73
+ },
74
+ "publishConfig": {
75
+ "access": "public"
76
+ }
72
77
  }
package/.dist/index.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var cors_1 = __importDefault(require("cors"));
7
- function initMiddleware(middleware) {
8
- return function (req, res, options) {
9
- return new Promise(function (resolve, reject) {
10
- middleware(options)(req, res, function (result) {
11
- if (result instanceof Error) {
12
- return reject(result);
13
- }
14
- return resolve(result);
15
- });
16
- });
17
- };
18
- }
19
- var NextCors = initMiddleware(cors_1.default);
20
- exports.default = NextCors;