@vafast/cors 0.0.1 → 0.0.3
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 +59 -29
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +7 -20
package/README.md
CHANGED
|
@@ -1,23 +1,39 @@
|
|
|
1
|
-
# @
|
|
2
|
-
|
|
1
|
+
# @vafast/cors
|
|
2
|
+
|
|
3
|
+
CORS middleware plugin for [Vafast](https://github.com/vafastjs/vafast) framework.
|
|
3
4
|
|
|
4
5
|
## Installation
|
|
6
|
+
|
|
5
7
|
```bash
|
|
6
|
-
bun add @
|
|
8
|
+
bun add @vafast/cors
|
|
9
|
+
# or
|
|
10
|
+
npm install @vafast/cors
|
|
7
11
|
```
|
|
8
12
|
|
|
9
13
|
## Example
|
|
10
|
-
```typescript
|
|
11
|
-
import { Elysia } from '@huyooo/elysia'
|
|
12
|
-
import { cors } from '@huyooo/elysia-cors'
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
```typescript
|
|
16
|
+
import { Server, createHandler } from 'vafast'
|
|
17
|
+
import { cors } from '@vafast/cors'
|
|
18
|
+
|
|
19
|
+
const server = new Server([
|
|
20
|
+
{
|
|
21
|
+
method: 'GET',
|
|
22
|
+
path: '/',
|
|
23
|
+
handler: createHandler(() => 'Hello World'),
|
|
24
|
+
middleware: [cors()]
|
|
25
|
+
}
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
fetch: (req: Request) => server.fetch(req)
|
|
30
|
+
}
|
|
17
31
|
```
|
|
18
32
|
|
|
19
|
-
##
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
20
35
|
### origin
|
|
36
|
+
|
|
21
37
|
@default `true`
|
|
22
38
|
|
|
23
39
|
Assign the **Access-Control-Allow-Origin** header.
|
|
@@ -25,33 +41,34 @@ Assign the **Access-Control-Allow-Origin** header.
|
|
|
25
41
|
Value can be one of the following:
|
|
26
42
|
- `string` - String of origin which will directly assign to `Access-Control-Allow-Origin`
|
|
27
43
|
|
|
28
|
-
- `boolean` - If set to true, `Access-Control-Allow-Origin` will be set to
|
|
44
|
+
- `boolean` - If set to true, `Access-Control-Allow-Origin` will be set to the request origin (accept all origin)
|
|
29
45
|
|
|
30
46
|
- `RegExp` - Pattern to use to test with request's url, will accept origin if matched.
|
|
31
47
|
|
|
32
48
|
- `Function` - Custom logic to validate origin acceptance or not. will accept origin if `true` is returned.
|
|
33
|
-
- Function will accepts `Context` just like `Handler`
|
|
34
49
|
```typescript
|
|
35
50
|
// Example usage
|
|
36
|
-
|
|
37
|
-
origin: (
|
|
51
|
+
cors({
|
|
52
|
+
origin: (request: Request) => {
|
|
53
|
+
const origin = request.headers.get('Origin')
|
|
54
|
+
return origin === 'https://example.com'
|
|
55
|
+
}
|
|
38
56
|
})
|
|
39
|
-
|
|
40
|
-
// Type Definition
|
|
41
|
-
type CORSOriginFn = (context: Context) => boolean | void
|
|
42
57
|
```
|
|
43
58
|
|
|
44
59
|
- `Array<string | RegExp | Function>` - Will try to find truthy value of all options above. Will accept Request if one is `true`.
|
|
45
60
|
|
|
46
61
|
### methods
|
|
47
|
-
|
|
62
|
+
|
|
63
|
+
@default `true`
|
|
48
64
|
|
|
49
65
|
Assign **Access-Control-Allow-Methods** header.
|
|
50
66
|
|
|
51
67
|
Value can be one of the following:
|
|
52
|
-
Accept:
|
|
53
68
|
- `undefined | null | ''` - Ignore all methods.
|
|
54
69
|
|
|
70
|
+
- `true` - Mirror the request method.
|
|
71
|
+
|
|
55
72
|
- `*` - Accept all methods.
|
|
56
73
|
|
|
57
74
|
- `HTTPMethod` - Will be directly set to **Access-Control-Allow-Methods**.
|
|
@@ -61,34 +78,41 @@ Accept:
|
|
|
61
78
|
- eg: ['GET', 'PUT', 'POST']
|
|
62
79
|
|
|
63
80
|
### allowedHeaders
|
|
64
|
-
|
|
81
|
+
|
|
82
|
+
@default `true`
|
|
65
83
|
|
|
66
84
|
Assign **Access-Control-Allow-Headers** header.
|
|
67
85
|
|
|
68
86
|
Allow incoming request with the specified headers.
|
|
69
87
|
|
|
70
88
|
Value can be one of the following:
|
|
89
|
+
- `true` - Mirror the request headers.
|
|
90
|
+
|
|
71
91
|
- `string`
|
|
72
|
-
- Expects either a single
|
|
92
|
+
- Expects either a single header or a comma-delimited string (eg: 'Content-Type, Authorization').
|
|
73
93
|
|
|
74
|
-
- `string[]` - Allow multiple
|
|
94
|
+
- `string[]` - Allow multiple headers.
|
|
75
95
|
- eg: ['Content-Type', 'Authorization']
|
|
76
96
|
|
|
77
|
-
###
|
|
78
|
-
|
|
97
|
+
### exposeHeaders
|
|
98
|
+
|
|
99
|
+
@default `true`
|
|
79
100
|
|
|
80
101
|
Assign **Access-Control-Exposed-Headers** header.
|
|
81
102
|
|
|
82
103
|
Return the specified headers to request in CORS mode.
|
|
83
104
|
|
|
84
105
|
Value can be one of the following:
|
|
106
|
+
- `true` - Mirror the request headers.
|
|
107
|
+
|
|
85
108
|
- `string`
|
|
86
|
-
- Expects either a single
|
|
109
|
+
- Expects either a single header or a comma-delimited string (eg: 'Content-Type, X-Powered-By').
|
|
87
110
|
|
|
88
|
-
- `string[]` - Allow multiple
|
|
111
|
+
- `string[]` - Allow multiple headers.
|
|
89
112
|
- eg: ['Content-Type', 'X-Powered-By']
|
|
90
113
|
|
|
91
114
|
### credentials
|
|
115
|
+
|
|
92
116
|
@default `true`
|
|
93
117
|
|
|
94
118
|
Assign **Access-Control-Allow-Credentials** header.
|
|
@@ -98,17 +122,23 @@ Allow incoming requests to send `credentials` header.
|
|
|
98
122
|
- `boolean` - Available if set to `true`.
|
|
99
123
|
|
|
100
124
|
### maxAge
|
|
125
|
+
|
|
101
126
|
@default `5`
|
|
102
127
|
|
|
103
128
|
Assign **Access-Control-Max-Age** header.
|
|
104
129
|
|
|
105
|
-
|
|
130
|
+
Duration in seconds to indicates how long the results of a preflight request can be cached.
|
|
106
131
|
|
|
107
|
-
- `number` - Duration in seconds
|
|
132
|
+
- `number` - Duration in seconds.
|
|
108
133
|
|
|
109
134
|
### preflight
|
|
135
|
+
|
|
110
136
|
@default `true`
|
|
111
137
|
|
|
112
|
-
|
|
138
|
+
Automatically handle OPTIONS preflight requests which response with `HTTP 204` and CORS headers.
|
|
113
139
|
|
|
114
140
|
- `boolean` - Available if set to `true`.
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import { empty } from "vafast";
|
|
2
3
|
var isBun = typeof new Headers()?.toJSON === "function";
|
|
3
4
|
var processHeaders = (headers) => {
|
|
4
5
|
if ("toJSON" in headers && typeof headers.toJSON === "function") {
|
|
@@ -109,7 +110,7 @@ var cors = (config) => {
|
|
|
109
110
|
response.headers.set("access-control-allow-credentials", "true");
|
|
110
111
|
};
|
|
111
112
|
const handlePreflight = async (request) => {
|
|
112
|
-
const response =
|
|
113
|
+
const response = empty(204);
|
|
113
114
|
handleOrigin(response, request);
|
|
114
115
|
handleMethod(
|
|
115
116
|
response,
|
|
@@ -133,7 +134,7 @@ var cors = (config) => {
|
|
|
133
134
|
};
|
|
134
135
|
return async (request, next) => {
|
|
135
136
|
if (preflight && request.method === "OPTIONS") {
|
|
136
|
-
const response2 =
|
|
137
|
+
const response2 = empty(204);
|
|
137
138
|
handleOrigin(response2, request);
|
|
138
139
|
handleMethod(
|
|
139
140
|
response2,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable no-case-declarations */\nimport type { Middleware } from 'vafast'\n\ntype Origin = string | RegExp | ((request: Request) => boolean | void)\n\nexport type HTTPMethod =\n\t| 'ACL'\n\t| 'BIND'\n\t| 'CHECKOUT'\n\t| 'CONNECT'\n\t| 'COPY'\n\t| 'DELETE'\n\t| 'GET'\n\t| 'HEAD'\n\t| 'LINK'\n\t| 'LOCK'\n\t| 'M-SEARCH'\n\t| 'MERGE'\n\t| 'MKACTIVITY'\n\t| 'MKCALENDAR'\n\t| 'MKCOL'\n\t| 'MOVE'\n\t| 'NOTIFY'\n\t| 'OPTIONS'\n\t| 'PATCH'\n\t| 'POST'\n\t| 'PROPFIND'\n\t| 'PROPPATCH'\n\t| 'PURGE'\n\t| 'PUT'\n\t| 'REBIND'\n\t| 'REPORT'\n\t| 'SEARCH'\n\t| 'SOURCE'\n\t| 'SUBSCRIBE'\n\t| 'TRACE'\n\t| 'UNBIND'\n\t| 'UNLINK'\n\t| 'UNLOCK'\n\t| 'UNSUBSCRIBE'\n\ntype MaybeArray<T> = T | T[]\n\ninterface CORSConfig {\n\t/**\n\t * @default `true`\n\t *\n\t * Assign the **Access-Control-Allow-Origin** header.\n\t *\n\t * Value can be one of the following:\n\t * - `string` - String of origin which will be directly assign to `Access-Control-Allow-Origin`\n\t *\n\t * - `boolean` - If set to true, `Access-Control-Allow-Origin` will be set to `*` (accept all origin)\n\t *\n\t * - `RegExp` - Pattern to use to test with request's url, will accept origin if matched.\n\t *\n\t * - `Function` - Custom logic to validate origin acceptance or not. will accept origin if `true` is returned.\n\t * - Function will accepts `Request` as parameter\n\t *\n\t * ```typescript\n\t * // ? Example usage\n\t * const corsMiddleware = cors({\n\t * origin: (request) => true\n\t * })\n\t *\n\t * // Type Definition\n\t * type CORSOriginFn = (request: Request) => boolean | void\n\t * ```\n\t *\n\t * - `Array<string | RegExp | Function>` - Will try to find truthy value of all options above. Will accept request if one is `true`.\n\t */\n\torigin?: Origin | boolean | Origin[]\n\t/**\n\t * @default `*`\n\t *\n\t * Assign **Access-Control-Allow-Methods** header.\n\t *\n\t * Value can be one of the following:\n\t * Accept:\n\t * - `undefined | null | ''` - Ignore all methods.\n\t *\n\t * - `*` - Accept all methods.\n\t *\n\t * - `HTTPMethod` - Will be directly set to **Access-Control-Allow-Methods**.\n\t * - Expects either a single method or a comma-delimited string (eg: 'GET, PUT, POST')\n\t *\n\t * - `HTTPMethod[]` - Allow multiple HTTP methods.\n\t * - eg: ['GET', 'PUT', 'POST']\n\t */\n\tmethods?:\n\t\t| boolean\n\t\t| undefined\n\t\t| null\n\t\t| ''\n\t\t| '*'\n\t\t| MaybeArray<HTTPMethod | (string & {})>\n\t/**\n\t * @default `*`\n\t *\n\t * Assign **Access-Control-Allow-Headers** header.\n\t *\n\t * Allow incoming request with the specified headers.\n\t *\n\t * Value can be one of the following:\n\t * - `string`\n\t * - Expects either a single method or a comma-delimited string (eg: 'Content-Type, Authorization').\n\t *\n\t * - `string[]` - Allow multiple HTTP methods.\n\t * - eg: ['Content-Type', 'Authorization']\n\t */\n\tallowedHeaders?: true | string | string[]\n\t/**\n\t * @default `*`\n\t *\n\t * Assign **Access-Control-Expose-Headers** header.\n\t *\n\t * Return the specified headers to request in CORS mode.\n\t *\n\t * Value can be one of the following:\n\t * - `string`\n\t * - Expects either a single method or a comma-delimited string (eg: 'Content-Type, 'X-Powered-By').\n\t *\n\t * - `string[]` - Allow multiple HTTP methods.\n\t * - eg: ['Content-Type', 'X-Powered-By']\n\t */\n\texposeHeaders?: true | string | string[]\n\t/**\n\t * @default `true`\n\t *\n\t * Assign **Access-Control-Allow-Credentials** header.\n\t *\n\t * Allow incoming requests to send `credentials` header.\n\t *\n\t * - `boolean` - Available if set to `true`.\n\t */\n\tcredentials?: boolean\n\t/**\n\t * @default `5`\n\t *\n\t * Assign **Access-Control-Max-Age** header.\n\t *\n\t * Allow incoming requests to send `credentials` header.\n\t *\n\t * - `number` - Duration in seconds to indicates how long the results of a preflight request can be cached.\n\t */\n\tmaxAge?: number\n\t/**\n\t * @default `true`\n\t *\n\t * Add `[OPTIONS] /*` handler to handle preflight request which response with `HTTP 204` and CORS hints.\n\t *\n\t * - `boolean` - Available if set to `true`.\n\t */\n\tpreflight?: boolean\n}\n\n// @ts-ignore\nconst isBun = typeof new Headers()?.toJSON === 'function'\n\n/**\n * This function is use when headers config is true.\n * Attempts to process headers based on request headers.\n */\nconst processHeaders = (headers: any) => {\n\t// Check if toJSON method exists (Bun specific)\n\tif ('toJSON' in headers && typeof headers.toJSON === 'function') {\n\t\treturn Object.keys(headers.toJSON()).join(', ')\n\t}\n\n\tlet keys = ''\n\n\tlet i = 0\n\theaders.forEach((_: any, key: string) => {\n\t\tif (i) keys = keys + ', ' + key\n\t\telse keys = key\n\n\t\ti++\n\t})\n\n\treturn keys\n}\n\nexport const cors = (config?: CORSConfig): Middleware => {\n\tlet {\n\t\torigin = true,\n\t\tmethods = true,\n\t\tallowedHeaders = true,\n\t\texposeHeaders = true,\n\t\tcredentials = true,\n\t\tmaxAge = 5,\n\t\tpreflight = true\n\t} = config ?? {}\n\n\tif (Array.isArray(allowedHeaders))\n\t\tallowedHeaders = allowedHeaders.join(', ')\n\n\tif (Array.isArray(exposeHeaders)) exposeHeaders = exposeHeaders.join(', ')\n\n\tconst origins =\n\t\ttypeof origin === 'boolean'\n\t\t\t? undefined\n\t\t\t: Array.isArray(origin)\n\t\t\t? origin\n\t\t\t: [origin]\n\n\tconst anyOrigin = origins?.some((o) => o === '*')\n\n\tconst originMap = <Record<string, true>>{}\n\tif (origins)\n\t\tfor (const origin of origins)\n\t\t\tif (typeof origin === 'string') originMap[origin] = true\n\n\tconst processOrigin = (\n\t\torigin: Origin,\n\t\trequest: Request,\n\t\tfrom: string\n\t): boolean => {\n\t\tif (Array.isArray(origin))\n\t\t\treturn origin.some((o) => processOrigin(o, request, from))\n\n\t\tswitch (typeof origin) {\n\t\t\tcase 'string':\n\t\t\t\tif (from in originMap) return true\n\n\t\t\t\tconst fromProtocol = from.indexOf('://')\n\t\t\t\tif (fromProtocol !== -1) from = from.slice(fromProtocol + 3)\n\n\t\t\t\treturn origin === from\n\n\t\t\tcase 'function':\n\t\t\t\treturn origin(request) === true\n\n\t\t\tcase 'object':\n\t\t\t\tif (origin instanceof RegExp) return origin.test(from)\n\t\t}\n\n\t\treturn false\n\t}\n\n\tconst handleOrigin = (response: Response, request: Request) => {\n\t\t// origin === `true` means any origin\n\t\tif (origin === true) {\n\t\t\tresponse.headers.set('vary', '*')\n\t\t\tresponse.headers.set(\n\t\t\t\t'access-control-allow-origin',\n\t\t\t\trequest.headers.get('Origin') || '*'\n\t\t\t)\n\n\t\t\treturn\n\t\t}\n\n\t\tif (anyOrigin) {\n\t\t\tresponse.headers.set('vary', '*')\n\t\t\tresponse.headers.set('access-control-allow-origin', '*')\n\n\t\t\treturn\n\t\t}\n\n\t\tif (!origins?.length) return\n\n\t\tconst headers: string[] = []\n\n\t\tif (origins.length) {\n\t\t\tconst from = request.headers.get('Origin') ?? ''\n\t\t\tfor (let i = 0; i < origins.length; i++) {\n\t\t\t\tconst value = processOrigin(origins[i]!, request, from)\n\t\t\t\tif (value === true) {\n\t\t\t\t\tresponse.headers.set('vary', origin ? 'Origin' : '*')\n\t\t\t\t\tresponse.headers.set(\n\t\t\t\t\t\t'access-control-allow-origin',\n\t\t\t\t\t\tfrom || '*'\n\t\t\t\t\t)\n\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tresponse.headers.set('vary', 'Origin')\n\t\tif (headers.length)\n\t\t\tresponse.headers.set(\n\t\t\t\t'access-control-allow-origin',\n\t\t\t\theaders.join(', ')\n\t\t\t)\n\t}\n\n\tconst handleMethod = (response: Response, method?: string | null) => {\n\t\tif (!method) return\n\n\t\tif (methods === true)\n\t\t\treturn response.headers.set(\n\t\t\t\t'access-control-allow-methods',\n\t\t\t\tmethod ?? '*'\n\t\t\t)\n\n\t\tif (methods === false || !methods?.length) return\n\n\t\tif (methods === '*')\n\t\t\treturn response.headers.set('access-control-allow-methods', '*')\n\n\t\tif (!Array.isArray(methods))\n\t\t\treturn response.headers.set('access-control-allow-methods', methods)\n\n\t\tresponse.headers.set('access-control-allow-methods', methods.join(', '))\n\t}\n\n\tconst setDefaultHeaders = (response: Response) => {\n\t\tif (typeof exposeHeaders === 'string')\n\t\t\tresponse.headers.set('access-control-expose-headers', exposeHeaders)\n\n\t\tif (typeof allowedHeaders === 'string')\n\t\t\tresponse.headers.set('access-control-allow-headers', allowedHeaders)\n\n\t\tif (credentials === true)\n\t\t\tresponse.headers.set('access-control-allow-credentials', 'true')\n\t}\n\n\tconst handlePreflight = async (request: Request): Promise<Response> => {\n\t\tconst response = new Response(null, { status: 204 })\n\n\t\thandleOrigin(response, request)\n\t\thandleMethod(\n\t\t\tresponse,\n\t\t\trequest.headers.get('access-control-request-method')\n\t\t)\n\n\t\tif (allowedHeaders === true || exposeHeaders === true) {\n\t\t\tif (allowedHeaders === true)\n\t\t\t\tresponse.headers.set(\n\t\t\t\t\t'access-control-allow-headers',\n\t\t\t\t\trequest.headers.get('access-control-request-headers') || ''\n\t\t\t\t)\n\n\t\t\tif (exposeHeaders === true)\n\t\t\t\tresponse.headers.set(\n\t\t\t\t\t'access-control-expose-headers',\n\t\t\t\t\tprocessHeaders(request.headers)\n\t\t\t\t)\n\t\t}\n\n\t\tif (maxAge)\n\t\t\tresponse.headers.set('access-control-max-age', maxAge.toString())\n\n\t\treturn response\n\t}\n\n\treturn async (request: Request, next: () => Promise<Response>) => {\n\t\t// Handle preflight requests\n\t\tif (preflight && request.method === 'OPTIONS') {\n\t\t\tconst response = new Response(null, { status: 204 })\n\n\t\t\thandleOrigin(response, request)\n\t\t\thandleMethod(\n\t\t\t\tresponse,\n\t\t\t\trequest.headers.get('access-control-request-method')\n\t\t\t)\n\n\t\t\tif (allowedHeaders === true || exposeHeaders === true) {\n\t\t\t\tif (allowedHeaders === true)\n\t\t\t\t\tresponse.headers.set(\n\t\t\t\t\t\t'access-control-allow-headers',\n\t\t\t\t\t\trequest.headers.get('access-control-request-headers') ||\n\t\t\t\t\t\t\t''\n\t\t\t\t\t)\n\n\t\t\t\tif (exposeHeaders === true)\n\t\t\t\t\tresponse.headers.set(\n\t\t\t\t\t\t'access-control-expose-headers',\n\t\t\t\t\t\tprocessHeaders(request.headers)\n\t\t\t\t\t)\n\t\t\t}\n\n\t\t\tif (maxAge)\n\t\t\t\tresponse.headers.set(\n\t\t\t\t\t'access-control-max-age',\n\t\t\t\t\tmaxAge.toString()\n\t\t\t\t)\n\n\t\t\treturn response\n\t\t}\n\n\t\t// Process CORS for actual requests\n\t\tconst response = await next()\n\n\t\thandleOrigin(response, request)\n\t\thandleMethod(response, request.method)\n\t\tsetDefaultHeaders(response)\n\n\t\tif (allowedHeaders === true || exposeHeaders === true) {\n\t\t\tconst headers = processHeaders(request.headers)\n\n\t\t\tif (allowedHeaders === true)\n\t\t\t\tresponse.headers.set('access-control-allow-headers', headers)\n\n\t\t\tif (exposeHeaders === true)\n\t\t\t\tresponse.headers.set('access-control-expose-headers', headers)\n\t\t}\n\n\t\treturn response\n\t}\n}\n\nexport default cors\n"],"mappings":";AA6JA,IAAM,QAAQ,OAAO,IAAI,QAAQ,GAAG,WAAW;AAM/C,IAAM,iBAAiB,CAAC,YAAiB;AAExC,MAAI,YAAY,WAAW,OAAO,QAAQ,WAAW,YAAY;AAChE,WAAO,OAAO,KAAK,QAAQ,OAAO,CAAC,EAAE,KAAK,IAAI;AAAA,EAC/C;AAEA,MAAI,OAAO;AAEX,MAAI,IAAI;AACR,UAAQ,QAAQ,CAAC,GAAQ,QAAgB;AACxC,QAAI,EAAG,QAAO,OAAO,OAAO;AAAA,QACvB,QAAO;AAEZ;AAAA,EACD,CAAC;AAED,SAAO;AACR;AAEO,IAAM,OAAO,CAAC,WAAoC;AACxD,MAAI;AAAA,IACH,SAAS;AAAA,IACT,UAAU;AAAA,IACV,iBAAiB;AAAA,IACjB,gBAAgB;AAAA,IAChB,cAAc;AAAA,IACd,SAAS;AAAA,IACT,YAAY;AAAA,EACb,IAAI,UAAU,CAAC;AAEf,MAAI,MAAM,QAAQ,cAAc;AAC/B,qBAAiB,eAAe,KAAK,IAAI;AAE1C,MAAI,MAAM,QAAQ,aAAa,EAAG,iBAAgB,cAAc,KAAK,IAAI;AAEzE,QAAM,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AAS,QAAQ,IAAI,iCAAiC,OAAO;AAAA,IAC/D;AAEA,WAAO;AAAA,EACR;AACD;AAEA,IAAO,gBAAQ;","names":["origin","response"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable no-case-declarations */\nimport type { Middleware } from 'vafast'\nimport { empty } from 'vafast'\n\ntype Origin = string | RegExp | ((request: Request) => boolean | void)\n\nexport type HTTPMethod =\n\t| 'ACL'\n\t| 'BIND'\n\t| 'CHECKOUT'\n\t| 'CONNECT'\n\t| 'COPY'\n\t| 'DELETE'\n\t| 'GET'\n\t| 'HEAD'\n\t| 'LINK'\n\t| 'LOCK'\n\t| 'M-SEARCH'\n\t| 'MERGE'\n\t| 'MKACTIVITY'\n\t| 'MKCALENDAR'\n\t| 'MKCOL'\n\t| 'MOVE'\n\t| 'NOTIFY'\n\t| 'OPTIONS'\n\t| 'PATCH'\n\t| 'POST'\n\t| 'PROPFIND'\n\t| 'PROPPATCH'\n\t| 'PURGE'\n\t| 'PUT'\n\t| 'REBIND'\n\t| 'REPORT'\n\t| 'SEARCH'\n\t| 'SOURCE'\n\t| 'SUBSCRIBE'\n\t| 'TRACE'\n\t| 'UNBIND'\n\t| 'UNLINK'\n\t| 'UNLOCK'\n\t| 'UNSUBSCRIBE'\n\ntype MaybeArray<T> = T | T[]\n\ninterface CORSConfig {\n\t/**\n\t * @default `true`\n\t *\n\t * Assign the **Access-Control-Allow-Origin** header.\n\t *\n\t * Value can be one of the following:\n\t * - `string` - String of origin which will be directly assign to `Access-Control-Allow-Origin`\n\t *\n\t * - `boolean` - If set to true, `Access-Control-Allow-Origin` will be set to `*` (accept all origin)\n\t *\n\t * - `RegExp` - Pattern to use to test with request's url, will accept origin if matched.\n\t *\n\t * - `Function` - Custom logic to validate origin acceptance or not. will accept origin if `true` is returned.\n\t * - Function will accepts `Request` as parameter\n\t *\n\t * ```typescript\n\t * // ? Example usage\n\t * const corsMiddleware = cors({\n\t * origin: (request) => true\n\t * })\n\t *\n\t * // Type Definition\n\t * type CORSOriginFn = (request: Request) => boolean | void\n\t * ```\n\t *\n\t * - `Array<string | RegExp | Function>` - Will try to find truthy value of all options above. Will accept request if one is `true`.\n\t */\n\torigin?: Origin | boolean | Origin[]\n\t/**\n\t * @default `*`\n\t *\n\t * Assign **Access-Control-Allow-Methods** header.\n\t *\n\t * Value can be one of the following:\n\t * Accept:\n\t * - `undefined | null | ''` - Ignore all methods.\n\t *\n\t * - `*` - Accept all methods.\n\t *\n\t * - `HTTPMethod` - Will be directly set to **Access-Control-Allow-Methods**.\n\t * - Expects either a single method or a comma-delimited string (eg: 'GET, PUT, POST')\n\t *\n\t * - `HTTPMethod[]` - Allow multiple HTTP methods.\n\t * - eg: ['GET', 'PUT', 'POST']\n\t */\n\tmethods?:\n\t\t| boolean\n\t\t| undefined\n\t\t| null\n\t\t| ''\n\t\t| '*'\n\t\t| MaybeArray<HTTPMethod | (string & {})>\n\t/**\n\t * @default `*`\n\t *\n\t * Assign **Access-Control-Allow-Headers** header.\n\t *\n\t * Allow incoming request with the specified headers.\n\t *\n\t * Value can be one of the following:\n\t * - `string`\n\t * - Expects either a single method or a comma-delimited string (eg: 'Content-Type, Authorization').\n\t *\n\t * - `string[]` - Allow multiple HTTP methods.\n\t * - eg: ['Content-Type', 'Authorization']\n\t */\n\tallowedHeaders?: true | string | string[]\n\t/**\n\t * @default `*`\n\t *\n\t * Assign **Access-Control-Expose-Headers** header.\n\t *\n\t * Return the specified headers to request in CORS mode.\n\t *\n\t * Value can be one of the following:\n\t * - `string`\n\t * - Expects either a single method or a comma-delimited string (eg: 'Content-Type, 'X-Powered-By').\n\t *\n\t * - `string[]` - Allow multiple HTTP methods.\n\t * - eg: ['Content-Type', 'X-Powered-By']\n\t */\n\texposeHeaders?: true | string | string[]\n\t/**\n\t * @default `true`\n\t *\n\t * Assign **Access-Control-Allow-Credentials** header.\n\t *\n\t * Allow incoming requests to send `credentials` header.\n\t *\n\t * - `boolean` - Available if set to `true`.\n\t */\n\tcredentials?: boolean\n\t/**\n\t * @default `5`\n\t *\n\t * Assign **Access-Control-Max-Age** header.\n\t *\n\t * Allow incoming requests to send `credentials` header.\n\t *\n\t * - `number` - Duration in seconds to indicates how long the results of a preflight request can be cached.\n\t */\n\tmaxAge?: number\n\t/**\n\t * @default `true`\n\t *\n\t * Add `[OPTIONS] /*` handler to handle preflight request which response with `HTTP 204` and CORS hints.\n\t *\n\t * - `boolean` - Available if set to `true`.\n\t */\n\tpreflight?: boolean\n}\n\n// @ts-ignore\nconst isBun = typeof new Headers()?.toJSON === 'function'\n\n/**\n * This function is use when headers config is true.\n * Attempts to process headers based on request headers.\n */\nconst processHeaders = (headers: any) => {\n\t// Check if toJSON method exists (Bun specific)\n\tif ('toJSON' in headers && typeof headers.toJSON === 'function') {\n\t\treturn Object.keys(headers.toJSON()).join(', ')\n\t}\n\n\tlet keys = ''\n\n\tlet i = 0\n\theaders.forEach((_: any, key: string) => {\n\t\tif (i) keys = keys + ', ' + key\n\t\telse keys = key\n\n\t\ti++\n\t})\n\n\treturn keys\n}\n\nexport const cors = (config?: CORSConfig): Middleware => {\n\tlet {\n\t\torigin = true,\n\t\tmethods = true,\n\t\tallowedHeaders = true,\n\t\texposeHeaders = true,\n\t\tcredentials = true,\n\t\tmaxAge = 5,\n\t\tpreflight = true\n\t} = config ?? {}\n\n\tif (Array.isArray(allowedHeaders))\n\t\tallowedHeaders = allowedHeaders.join(', ')\n\n\tif (Array.isArray(exposeHeaders)) exposeHeaders = exposeHeaders.join(', ')\n\n\tconst origins =\n\t\ttypeof origin === 'boolean'\n\t\t\t? undefined\n\t\t\t: Array.isArray(origin)\n\t\t\t? origin\n\t\t\t: [origin]\n\n\tconst anyOrigin = origins?.some((o) => o === '*')\n\n\tconst originMap = <Record<string, true>>{}\n\tif (origins)\n\t\tfor (const origin of origins)\n\t\t\tif (typeof origin === 'string') originMap[origin] = true\n\n\tconst processOrigin = (\n\t\torigin: Origin,\n\t\trequest: Request,\n\t\tfrom: string\n\t): boolean => {\n\t\tif (Array.isArray(origin))\n\t\t\treturn origin.some((o) => processOrigin(o, request, from))\n\n\t\tswitch (typeof origin) {\n\t\t\tcase 'string':\n\t\t\t\tif (from in originMap) return true\n\n\t\t\t\tconst fromProtocol = from.indexOf('://')\n\t\t\t\tif (fromProtocol !== -1) from = from.slice(fromProtocol + 3)\n\n\t\t\t\treturn origin === from\n\n\t\t\tcase 'function':\n\t\t\t\treturn origin(request) === true\n\n\t\t\tcase 'object':\n\t\t\t\tif (origin instanceof RegExp) return origin.test(from)\n\t\t}\n\n\t\treturn false\n\t}\n\n\tconst handleOrigin = (response: Response, request: Request) => {\n\t\t// origin === `true` means any origin\n\t\tif (origin === true) {\n\t\t\tresponse.headers.set('vary', '*')\n\t\t\tresponse.headers.set(\n\t\t\t\t'access-control-allow-origin',\n\t\t\t\trequest.headers.get('Origin') || '*'\n\t\t\t)\n\n\t\t\treturn\n\t\t}\n\n\t\tif (anyOrigin) {\n\t\t\tresponse.headers.set('vary', '*')\n\t\t\tresponse.headers.set('access-control-allow-origin', '*')\n\n\t\t\treturn\n\t\t}\n\n\t\tif (!origins?.length) return\n\n\t\tconst headers: string[] = []\n\n\t\tif (origins.length) {\n\t\t\tconst from = request.headers.get('Origin') ?? ''\n\t\t\tfor (let i = 0; i < origins.length; i++) {\n\t\t\t\tconst value = processOrigin(origins[i]!, request, from)\n\t\t\t\tif (value === true) {\n\t\t\t\t\tresponse.headers.set('vary', origin ? 'Origin' : '*')\n\t\t\t\t\tresponse.headers.set(\n\t\t\t\t\t\t'access-control-allow-origin',\n\t\t\t\t\t\tfrom || '*'\n\t\t\t\t\t)\n\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tresponse.headers.set('vary', 'Origin')\n\t\tif (headers.length)\n\t\t\tresponse.headers.set(\n\t\t\t\t'access-control-allow-origin',\n\t\t\t\theaders.join(', ')\n\t\t\t)\n\t}\n\n\tconst handleMethod = (response: Response, method?: string | null) => {\n\t\tif (!method) return\n\n\t\tif (methods === true)\n\t\t\treturn response.headers.set(\n\t\t\t\t'access-control-allow-methods',\n\t\t\t\tmethod ?? '*'\n\t\t\t)\n\n\t\tif (methods === false || !methods?.length) return\n\n\t\tif (methods === '*')\n\t\t\treturn response.headers.set('access-control-allow-methods', '*')\n\n\t\tif (!Array.isArray(methods))\n\t\t\treturn response.headers.set('access-control-allow-methods', methods)\n\n\t\tresponse.headers.set('access-control-allow-methods', methods.join(', '))\n\t}\n\n\tconst setDefaultHeaders = (response: Response) => {\n\t\tif (typeof exposeHeaders === 'string')\n\t\t\tresponse.headers.set('access-control-expose-headers', exposeHeaders)\n\n\t\tif (typeof allowedHeaders === 'string')\n\t\t\tresponse.headers.set('access-control-allow-headers', allowedHeaders)\n\n\t\tif (credentials === true)\n\t\t\tresponse.headers.set('access-control-allow-credentials', 'true')\n\t}\n\n\tconst handlePreflight = async (request: Request): Promise<Response> => {\n\t\tconst response = empty(204)\n\n\t\thandleOrigin(response, request)\n\t\thandleMethod(\n\t\t\tresponse,\n\t\t\trequest.headers.get('access-control-request-method')\n\t\t)\n\n\t\tif (allowedHeaders === true || exposeHeaders === true) {\n\t\t\tif (allowedHeaders === true)\n\t\t\t\tresponse.headers.set(\n\t\t\t\t\t'access-control-allow-headers',\n\t\t\t\t\trequest.headers.get('access-control-request-headers') || ''\n\t\t\t\t)\n\n\t\t\tif (exposeHeaders === true)\n\t\t\t\tresponse.headers.set(\n\t\t\t\t\t'access-control-expose-headers',\n\t\t\t\t\tprocessHeaders(request.headers)\n\t\t\t\t)\n\t\t}\n\n\t\tif (maxAge)\n\t\t\tresponse.headers.set('access-control-max-age', maxAge.toString())\n\n\t\treturn response\n\t}\n\n\treturn async (request: Request, next: () => Promise<Response>) => {\n\t\t// Handle preflight requests\n\t\tif (preflight && request.method === 'OPTIONS') {\n\t\t\tconst response = empty(204)\n\n\t\t\thandleOrigin(response, request)\n\t\t\thandleMethod(\n\t\t\t\tresponse,\n\t\t\t\trequest.headers.get('access-control-request-method')\n\t\t\t)\n\n\t\t\tif (allowedHeaders === true || exposeHeaders === true) {\n\t\t\t\tif (allowedHeaders === true)\n\t\t\t\t\tresponse.headers.set(\n\t\t\t\t\t\t'access-control-allow-headers',\n\t\t\t\t\t\trequest.headers.get('access-control-request-headers') ||\n\t\t\t\t\t\t\t''\n\t\t\t\t\t)\n\n\t\t\t\tif (exposeHeaders === true)\n\t\t\t\t\tresponse.headers.set(\n\t\t\t\t\t\t'access-control-expose-headers',\n\t\t\t\t\t\tprocessHeaders(request.headers)\n\t\t\t\t\t)\n\t\t\t}\n\n\t\t\tif (maxAge)\n\t\t\t\tresponse.headers.set(\n\t\t\t\t\t'access-control-max-age',\n\t\t\t\t\tmaxAge.toString()\n\t\t\t\t)\n\n\t\t\treturn response\n\t\t}\n\n\t\t// Process CORS for actual requests\n\t\tconst response = await next()\n\n\t\thandleOrigin(response, request)\n\t\thandleMethod(response, request.method)\n\t\tsetDefaultHeaders(response)\n\n\t\tif (allowedHeaders === true || exposeHeaders === true) {\n\t\t\tconst headers = processHeaders(request.headers)\n\n\t\t\tif (allowedHeaders === true)\n\t\t\t\tresponse.headers.set('access-control-allow-headers', headers)\n\n\t\t\tif (exposeHeaders === true)\n\t\t\t\tresponse.headers.set('access-control-expose-headers', headers)\n\t\t}\n\n\t\treturn response\n\t}\n}\n\nexport default cors\n"],"mappings":";AAEA,SAAS,aAAa;AA4JtB,IAAM,QAAQ,OAAO,IAAI,QAAQ,GAAG,WAAW;AAM/C,IAAM,iBAAiB,CAAC,YAAiB;AAExC,MAAI,YAAY,WAAW,OAAO,QAAQ,WAAW,YAAY;AAChE,WAAO,OAAO,KAAK,QAAQ,OAAO,CAAC,EAAE,KAAK,IAAI;AAAA,EAC/C;AAEA,MAAI,OAAO;AAEX,MAAI,IAAI;AACR,UAAQ,QAAQ,CAAC,GAAQ,QAAgB;AACxC,QAAI,EAAG,QAAO,OAAO,OAAO;AAAA,QACvB,QAAO;AAEZ;AAAA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ED,aAAOA;AAAA,IACR;AAGA,UAAM,WAAW,MAAM,KAAK;AAE5B,iBAAa,UAAU,OAAO;AAC9B,iBAAa,UAAU,QAAQ,MAAM;AACrC,sBAAkB,QAAQ;AAE1B,QAAI,mBAAmB,QAAQ,kBAAkB,MAAM;AACtD,YAAM,UAAU,eAAe,QAAQ,OAAO;AAE9C,UAAI,mBAAmB;AACtB,iBAAS,QAAQ,IAAI,gCAAgC,OAAO;AAE7D,UAAI,kBAAkB;AACrB,iBAAS,QAAQ,IAAI,iCAAiC,OAAO;AAAA,IAC/D;AAEA,WAAO;AAAA,EACR;AACD;AAEA,IAAO,gBAAQ;","names":["origin","response"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vafast/cors",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "CORS middleware plugin for Vafast framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
21
|
"import": "./dist/index.js",
|
|
22
|
-
"require": "./dist/index.js",
|
|
23
22
|
"default": "./dist/index.js"
|
|
24
23
|
}
|
|
25
24
|
},
|
|
@@ -31,19 +30,10 @@
|
|
|
31
30
|
"cors"
|
|
32
31
|
],
|
|
33
32
|
"scripts": {
|
|
34
|
-
"clean": "rimraf dist",
|
|
35
33
|
"build": "tsup",
|
|
36
|
-
"dev": "
|
|
37
|
-
"test": "
|
|
38
|
-
"
|
|
39
|
-
"lint": "eslint . --ext .ts",
|
|
40
|
-
"lint:fix": "eslint . --ext .ts --fix",
|
|
41
|
-
"type-check": "tsc --noEmit",
|
|
42
|
-
"prepublishOnly": "npm run build && npm run test",
|
|
43
|
-
"release": "npm run build && npm run test && npm publish --access=public",
|
|
44
|
-
"release:patch": "npm version patch && npm run release && git push && git push --tags",
|
|
45
|
-
"release:minor": "npm version minor && npm run release && git push && git push --tags",
|
|
46
|
-
"release:major": "npm version major && npm run release && git push && git push --tags"
|
|
34
|
+
"dev": "npx tsx watch example/index.ts",
|
|
35
|
+
"test": "npx vitest run",
|
|
36
|
+
"release": "npm run build && npm run test && npx bumpp && npm publish --access=public"
|
|
47
37
|
},
|
|
48
38
|
"license": "MIT",
|
|
49
39
|
"files": [
|
|
@@ -52,18 +42,15 @@
|
|
|
52
42
|
"LICENSE"
|
|
53
43
|
],
|
|
54
44
|
"devDependencies": {
|
|
55
|
-
"@types/bun": "^1.1.2",
|
|
56
45
|
"@types/debug": "^4.1.12",
|
|
57
46
|
"@types/node": "^24.3.0",
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
|
59
|
-
"@typescript-eslint/parser": "^7.9.0",
|
|
60
|
-
"eslint": "^9.2.0",
|
|
61
47
|
"rimraf": "^6.0.1",
|
|
62
48
|
"tsup": "^8.5.1",
|
|
63
49
|
"typescript": "^5.4.5",
|
|
64
|
-
"vafast": "^0.3.
|
|
50
|
+
"vafast": "^0.3.10",
|
|
51
|
+
"vitest": "^4.0.16"
|
|
65
52
|
},
|
|
66
53
|
"peerDependencies": {
|
|
67
|
-
"vafast": "
|
|
54
|
+
"vafast": "^0.3.10"
|
|
68
55
|
}
|
|
69
56
|
}
|