@aomex/cors 0.0.3 → 0.0.5
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/CHANGELOG.md +4 -24
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
1
|
# @aomex/cors
|
|
2
2
|
|
|
3
|
-
## 0.0.
|
|
3
|
+
## 0.0.5
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- [`
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
- @aomex/web@0.0.5
|
|
11
|
-
- @aomex/core@0.0.4
|
|
12
|
-
|
|
13
|
-
## 0.0.2
|
|
14
|
-
|
|
15
|
-
### Patch Changes
|
|
16
|
-
|
|
17
|
-
- Updated dependencies [[`121253a`](https://github.com/aomex/aomex/commit/121253a6fc203e427bfd25e82d713bec6ac13b38), [`59dc183`](https://github.com/aomex/aomex/commit/59dc183bcec9b7221c18865563b38cba5d82869b), [`8cb74fd`](https://github.com/aomex/aomex/commit/8cb74fdd27626037aa9bc80cb2930e4f0d67f8e6), [`d834392`](https://github.com/aomex/aomex/commit/d834392b1e0f6333d66d11378d9f4ceb813a58a9), [`91feda4`](https://github.com/aomex/aomex/commit/91feda457dfa8bd8dd2c8f38bfaaf4f7f2f7702f)]:
|
|
18
|
-
- @aomex/web@0.0.4
|
|
19
|
-
- @aomex/core@0.0.3
|
|
20
|
-
|
|
21
|
-
## 0.0.1
|
|
22
|
-
|
|
23
|
-
### Patch Changes
|
|
24
|
-
|
|
25
|
-
- [`8a6f70c`](https://github.com/aomex/aomex/commit/8a6f70c32145b26b1896e976bc6f6454516c7a4d) Thanks [@geekact](https://github.com/geekact)! - 增加 web 插件 cors
|
|
26
|
-
|
|
27
|
-
- Updated dependencies [[`4735157`](https://github.com/aomex/aomex/commit/4735157c52d0abecc41d6c7f416280ebfd6ee696), [`d6ac7b5`](https://github.com/aomex/aomex/commit/d6ac7b5403334b51fa15dbe82dd6b5b6d048f661), [`9254754`](https://github.com/aomex/aomex/commit/9254754d234fc0062eb5d600284ee8453825306c), [`d1ce4e2`](https://github.com/aomex/aomex/commit/d1ce4e2276f93c44e67ea06666d048917fa94e53), [`6056f55`](https://github.com/aomex/aomex/commit/6056f556577865220d6b5be2a4eafad9e4dbf8d4), [`1c67399`](https://github.com/aomex/aomex/commit/1c673992c4b313c2accb4cbc1fc66537a9886c29), [`352642a`](https://github.com/aomex/aomex/commit/352642abf2ccb3fe97e2d83a691d8428ccfc9758)]:
|
|
28
|
-
- @aomex/web@0.0.3
|
|
29
|
-
- @aomex/core@0.0.2
|
|
7
|
+
- Updated dependencies [[`bbc8dda`](https://github.com/aomex/aomex/commit/bbc8dda9f0876c3402608133085350cc693def6f), [`ceb2d82`](https://github.com/aomex/aomex/commit/ceb2d8269755dca3f79b755224259b8a99bc65d0)]:
|
|
8
|
+
- @aomex/core@0.0.6
|
|
9
|
+
- @aomex/web@0.0.7
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface CorsOptions {
|
|
|
6
6
|
*
|
|
7
7
|
* @remarks
|
|
8
8
|
* If a function is provided, it will be called for each request with
|
|
9
|
-
* the
|
|
9
|
+
* the web context object. It may return a string or a promise that
|
|
10
10
|
* will resolve with a string.
|
|
11
11
|
*/
|
|
12
12
|
origin?: ((ctx: WebContext) => string) | ((ctx: WebContext) => PromiseLike<string>) | string;
|
|
@@ -32,7 +32,7 @@ interface CorsOptions {
|
|
|
32
32
|
*
|
|
33
33
|
* @remarks
|
|
34
34
|
* If a function is provided, it will be called for each request with
|
|
35
|
-
* the
|
|
35
|
+
* the web context object. It may return a boolean or a promise that
|
|
36
36
|
* will resolve with a boolean.
|
|
37
37
|
*/
|
|
38
38
|
credentials?: ((ctx: WebContext) => boolean) | ((ctx: WebContext) => PromiseLike<boolean>) | boolean;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { HttpError, WebContext, WebMiddleware } from '@aomex/web';\nimport { middleware } from '@aomex/core';\n\nexport interface CorsOptions {\n /**\n * `Access-Control-Allow-Origin`, default is request Origin header.\n *\n * @remarks\n * If a function is provided, it will be called for each request with\n * the
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { HttpError, WebContext, WebMiddleware } from '@aomex/web';\nimport { middleware } from '@aomex/core';\n\nexport interface CorsOptions {\n /**\n * `Access-Control-Allow-Origin`, default is request Origin header.\n *\n * @remarks\n * If a function is provided, it will be called for each request with\n * the web context object. It may return a string or a promise that\n * will resolve with a string.\n */\n origin?:\n | ((ctx: WebContext) => string)\n | ((ctx: WebContext) => PromiseLike<string>)\n | string;\n\n /**\n * `Access-Control-Allow-Methods`, default is\n * 'GET,HEAD,PUT,POST,DELETE,PATCH'\n */\n allowMethods?: string[] | string;\n\n /**\n * `Access-Control-Expose-Headers`\n */\n exposeHeaders?: string[] | string;\n\n /**\n * `Access-Control-Allow-Headers`\n */\n allowHeaders?: string[] | string;\n\n /**\n * `Access-Control-Max-Age` in seconds\n */\n maxAge?: number | string;\n\n /**\n * `Access-Control-Allow-Credentials`\n *\n * @remarks\n * If a function is provided, it will be called for each request with\n * the web context object. It may return a boolean or a promise that\n * will resolve with a boolean.\n */\n credentials?:\n | ((ctx: WebContext) => boolean)\n | ((ctx: WebContext) => PromiseLike<boolean>)\n | boolean;\n\n /**\n * Add set headers to `err.header` if an error is thrown\n */\n keepHeadersOnError?: boolean;\n\n /**\n * Add `Cross-Origin-Opener-Policy` & `Cross-Origin-Embedder-Policy` to response headers\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/Planned_changes\n */\n secureContext?: boolean;\n\n /**\n * Handle `Access-Control-Request-Private-Network` request by return `Access-Control-Allow-Private-Network`\n *\n * @see https://wicg.github.io/private-network-access/\n */\n privateNetworkAccess?: boolean;\n}\n\nconst defaults: CorsOptions = {\n allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',\n secureContext: false,\n};\n\nexport const cors = (options: CorsOptions = {}): WebMiddleware => {\n options = {\n ...defaults,\n ...options,\n };\n\n (<const>['exposeHeaders', 'allowMethods', 'allowHeaders']).forEach((key) => {\n const value = options[key];\n if (Array.isArray(value)) {\n options[key] = value.join(',');\n }\n });\n\n if (options.maxAge) {\n options.maxAge = String(options.maxAge);\n }\n\n options.keepHeadersOnError = options.keepHeadersOnError !== false;\n\n return middleware.web(async (ctx, next) => {\n const { request, response } = ctx;\n const requestOrigin = request.headers['origin'];\n\n // Always set Vary header\n // https://github.com/rs/cors/issues/10\n response.vary('Origin');\n\n if (!requestOrigin) return next();\n\n let origin: string;\n if (typeof options.origin === 'function') {\n origin = await options.origin(ctx);\n if (!origin) return next();\n } else {\n origin = options.origin || requestOrigin;\n }\n\n let credentials;\n if (typeof options.credentials === 'function') {\n credentials = await options.credentials(ctx);\n } else {\n credentials = !!options.credentials;\n }\n\n const headersSet: Record<string, any> = {};\n\n function setAndRecordHeader(key: string, value: any) {\n response.setHeader(key, value);\n headersSet[key] = value;\n }\n\n if (request.method !== 'OPTIONS') {\n // Simple Cross-Origin Request, Actual Request, and Redirects\n setAndRecordHeader('Access-Control-Allow-Origin', origin);\n credentials &&\n setAndRecordHeader('Access-Control-Allow-Credentials', 'true');\n\n if (options.exposeHeaders) {\n setAndRecordHeader(\n 'Access-Control-Expose-Headers',\n options.exposeHeaders,\n );\n }\n\n if (options.secureContext) {\n setAndRecordHeader('Cross-Origin-Opener-Policy', 'same-origin');\n setAndRecordHeader('Cross-Origin-Embedder-Policy', 'require-corp');\n }\n\n if (!options.keepHeadersOnError) return next();\n\n return next().catch((err: HttpError) => {\n const errHeadersSet = err.headers || {};\n const varyWithOrigin = response.varyAppend(\n errHeadersSet['vary'] || errHeadersSet['Vary'] || '',\n 'Origin',\n );\n delete errHeadersSet['Vary'];\n\n err.headers = {\n ...errHeadersSet,\n ...headersSet,\n ...{ vary: varyWithOrigin },\n };\n\n return Promise.reject(err);\n });\n } else {\n if (!request.headers['access-control-request-method']) return next();\n\n response.setHeader('Access-Control-Allow-Origin', origin);\n\n if (credentials === true) {\n response.setHeader('Access-Control-Allow-Credentials', 'true');\n }\n\n if (options.maxAge) {\n response.setHeader('Access-Control-Max-Age', options.maxAge);\n }\n\n if (\n options.privateNetworkAccess &&\n request.headers['access-control-request-private-network']\n ) {\n response.setHeader('Access-Control-Allow-Private-Network', 'true');\n }\n\n if (options.allowMethods) {\n response.setHeader(\n 'Access-Control-Allow-Methods',\n options.allowMethods,\n );\n }\n\n if (options.secureContext) {\n setAndRecordHeader('Cross-Origin-Opener-Policy', 'same-origin');\n setAndRecordHeader('Cross-Origin-Embedder-Policy', 'require-corp');\n }\n\n const allowHeaders =\n options.allowHeaders ||\n request.headers['access-control-request-headers'];\n if (allowHeaders) {\n response.setHeader('Access-Control-Allow-Headers', allowHeaders);\n }\n\n ctx.send(204);\n }\n });\n};\n"],"mappings":";AACA,SAAS,kBAAkB;AAsE3B,IAAM,WAAwB;AAAA,EAC5B,cAAc;AAAA,EACd,eAAe;AACjB;AAEO,IAAM,OAAO,CAAC,UAAuB,CAAC,MAAqB;AAChE,YAAU;AAAA,IACR,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AAEA,EAAQ,CAAC,iBAAiB,gBAAgB,cAAc,EAAG,QAAQ,CAAC,QAAQ;AAC1E,UAAM,QAAQ,QAAQ,GAAG;AACzB,QAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,cAAQ,GAAG,IAAI,MAAM,KAAK,GAAG;AAAA,IAC/B;AAAA,EACF,CAAC;AAED,MAAI,QAAQ,QAAQ;AAClB,YAAQ,SAAS,OAAO,QAAQ,MAAM;AAAA,EACxC;AAEA,UAAQ,qBAAqB,QAAQ,uBAAuB;AAE5D,SAAO,WAAW,IAAI,OAAO,KAAK,SAAS;A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;AAEA,eAAO,QAAQ,OAAO,GAAG;AAAA,MAC3B,CAAC;AAAA,IACH,OAAO;AACL,UAAI,CAAC,QAAQ,QAAQ,+BAA+B;AAAG,eAAO,KAAK;AAEnE,eAAS,UAAU,+BAA+B,MAAM;AAExD,UAAI,gBAAgB,MAAM;AACxB,iBAAS,UAAU,oCAAoC,MAAM;AAAA,MAC/D;AAEA,UAAI,QAAQ,QAAQ;AAClB,iBAAS,UAAU,0BAA0B,QAAQ,MAAM;AAAA,MAC7D;AAEA,UACE,QAAQ,wBACR,QAAQ,QAAQ,wCAAwC,GACxD;AACA,iBAAS,UAAU,wCAAwC,MAAM;AAAA,MACnE;AAEA,UAAI,QAAQ,cAAc;AACxB,iBAAS;AAAA,UACP;AAAA,UACA,QAAQ;AAAA,QACV;AAAA,MACF;AAEA,UAAI,QAAQ,eAAe;AACzB,2BAAmB,8BAA8B,aAAa;AAC9D,2BAAmB,gCAAgC,cAAc;AAAA,MACnE;AAEA,YAAM,eACJ,QAAQ,gBACR,QAAQ,QAAQ,gCAAgC;AAClD,UAAI,cAAc;AAChB,iBAAS,UAAU,gCAAgC,YAAY;AAAA,MACjE;AAEA,UAAI,KAAK,GAAG;AAAA,IACd;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex/cors",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "跨站资源共享",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cors"
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@aomex/core": "^0.0.
|
|
33
|
-
"@aomex/web": "^0.0.
|
|
32
|
+
"@aomex/core": "^0.0.6",
|
|
33
|
+
"@aomex/web": "^0.0.7"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@aomex/core": "^0.0.
|
|
37
|
-
"@aomex/web": "^0.0.
|
|
36
|
+
"@aomex/core": "^0.0.6",
|
|
37
|
+
"@aomex/web": "^0.0.7"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {}
|
|
40
40
|
}
|