nextjs-cors 2.2.0 → 3.0.0-alpha.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
@@ -21,13 +21,13 @@
21
21
 
22
22
  ```bash
23
23
  # Using npm
24
- npm install nextjs-cors@latest
24
+ npm install nextjs-cors@3.0.0-alpha
25
25
 
26
26
  # Using yarn
27
- yarn add nextjs-cors@latest
27
+ yarn add nextjs-cors@3.0.0-alpha
28
28
 
29
29
  # Using pnpm
30
- pnpm add nextjs-cors@latest
30
+ pnpm add nextjs-cors@3.0.0-alpha
31
31
  ```
32
32
 
33
33
  ## Usage
@@ -37,20 +37,20 @@ nextjs-cors uses the cors package, so we invite you to check the documentation h
37
37
  > pages/api/whoami.{ts,js}
38
38
 
39
39
  ```ts
40
- import NextCors from 'nextjs-cors';
40
+ import NextCors from 'nextjs-cors'
41
41
 
42
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!' });
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!' })
54
54
  }
55
55
  ```
56
56
 
@@ -0,0 +1 @@
1
+ export * from '@next-cors/core';
package/dist/index.d.ts CHANGED
@@ -1,4 +1 @@
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
+ export * from '@next-cors/core';
package/dist/index.js CHANGED
@@ -1,8 +1,2 @@
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
- }
1
+ "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(r,o,f,x)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of c(o))!d.call(r,e)&&e!==f&&a(r,e,{get:()=>o[e],enumerable:!(x=b(o,e))||x.enumerable});return r},t=(r,o,f)=>(p(r,o,"default"),f&&p(f,o,"default"));var g=r=>p(a({},"__esModule",{value:!0}),r);var m={};module.exports=g(m);t(m,require("@next-cors/core"),module.exports);0&&(module.exports={...require("@next-cors/core")});
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from '@next-cors/core'\n"],"mappings":"iaAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAAAE,EAAAF,EAAc,2BAAd","names":["src_exports","__toCommonJS","__reExport"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export*from"@next-cors/core";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from '@next-cors/core'\n"],"mappings":"AAAA,WAAc","names":[]}
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "nextjs-cors",
3
- "version": "2.2.0",
4
- "private": false,
3
+ "version": "3.0.0-alpha.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",
@@ -9,7 +8,8 @@
9
8
  "nextjs-express-cors",
10
9
  "next-cors",
11
10
  "cors-server",
12
- "cors"
11
+ "cors",
12
+ "nextjs-cors"
13
13
  ],
14
14
  "homepage": "https://github.com/yonycalsin/nextjs-cors#readme",
15
15
  "bugs": {
@@ -22,82 +22,37 @@
22
22
  "license": "MIT",
23
23
  "author": "Yony Calsin",
24
24
  "main": "dist/index.js",
25
- "module": "dist/nextjs-cors.esm.js",
25
+ "module": "dist/index.mjs",
26
26
  "typings": "dist/index.d.ts",
27
27
  "files": [
28
28
  "dist",
29
29
  "package.json",
30
30
  "README.md"
31
31
  ],
32
- "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
32
  "lint-staged": {
53
33
  "*.{ts,js}": [
54
34
  "eslint --fix"
55
35
  ]
56
36
  },
57
37
  "dependencies": {
58
- "cors": "^2.8.5"
38
+ "@next-cors/core": "0.0.1"
59
39
  },
60
40
  "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"
41
+ "@tsconfig/node20": "20.1.2",
42
+ "tsup": "8.0.1",
43
+ "typescript": "5.3.3"
74
44
  },
75
45
  "peerDependencies": {
76
- "next": "^8.1.1-canary.54 || ^9.0.0 || ^10.0.0-0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0"
46
+ "next": "^8.1.1-canary.54 || ^9.0.0 || ^10.0.0-0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0"
77
47
  },
78
48
  "publishConfig": {
79
49
  "access": "public"
80
50
  },
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
- ]
95
- }
96
- ],
97
- "@semantic-release/changelog"
98
- ]
99
- },
100
- "volta": {
101
- "node": "14.17.0"
51
+ "scripts": {
52
+ "clean": "rimraf dist",
53
+ "lint:ts": "tsc --noEmit",
54
+ "dev": "tsup-node --watch",
55
+ "build": "tsup-node",
56
+ "test": "echo \"Testing\""
102
57
  }
103
- }
58
+ }
@@ -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;;;;"}