Skip to content

Commit

Permalink
🧹 chore: using response null #47
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Feb 9, 2024
1 parent 7ce6d9a commit c069ff9
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 52 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@

# 1.0.0-beta.0 - 6 Feb 2024
Change:
- Add support for Elysia 1.0


# 0.8.0 - 23 Dec 2023
Change:
- Add support for Elysia 0.8

# 0.8.0-rc.1 - 21 Dec 2023
Improvement:
- Using `Elysia.headers` to set default headers
Expand Down
Binary file modified bun.lockb
Binary file not shown.
90 changes: 45 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
{
"name": "@elysiajs/cors",
"version": "0.8.0",
"description": "Plugin for Elysia that for Cross Origin Requests (CORs)",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
"email": "[email protected]"
},
"repository": {
"type": "git",
"url": "https://github.com/elysiajs/elysia-cors"
},
"exports": {
"bun": "./dist/index.js",
"node": "./dist/cjs/index.js",
"require": "./dist/cjs/index.js",
"import": "./dist/index.js",
"default": "./dist/cjs/index.js"
},
"types": "./src/index.ts",
"homepage": "https://github.com/elysiajs/elysia-cors",
"keywords": [
"elysia",
"cors"
],
"license": "MIT",
"scripts": {
"dev": "bun run --watch example/index.ts",
"test": "bun test && npm run test:node",
"test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
"build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
"release": "npm run build && npm run test && npm publish --access public"
},
"devDependencies": {
"@types/node": "^18.11.7",
"bun-types": "^1.0.2",
"elysia": "0.8.0",
"eslint": "^8.26.0",
"rimraf": "^3.0.2",
"typescript": "^5.2.2"
},
"peerDependencies": {
"elysia": ">= 0.8.0"
}
}
"name": "@elysiajs/cors",
"version": "1.0.0-beta.1",
"description": "Plugin for Elysia that for Cross Origin Requests (CORs)",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
"email": "[email protected]"
},
"repository": {
"type": "git",
"url": "https://github.com/elysiajs/elysia-cors"
},
"exports": {
"bun": "./dist/index.js",
"node": "./dist/cjs/index.js",
"require": "./dist/cjs/index.js",
"import": "./dist/index.js",
"default": "./dist/cjs/index.js"
},
"types": "./src/index.ts",
"homepage": "https://github.com/elysiajs/elysia-cors",
"keywords": [
"elysia",
"cors"
],
"license": "MIT",
"scripts": {
"dev": "bun run --watch example/index.ts",
"test": "bun test && npm run test:node",
"test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
"build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
"release": "npm run build && npm run test && npm publish --access public"
},
"devDependencies": {
"@types/bun": "^1.0.4",
"@types/node": "^18.11.7",
"elysia": "1.0.0-beta.1",
"eslint": "^8.26.0",
"rimraf": "^3.0.2",
"typescript": "^5.2.2"
},
"peerDependencies": {
"elysia": ">= 1.0.0-beta.1"
}
}
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const cors = (
if (value === true) {
set.headers['Vary'] = origin ? 'Origin' : '*'
set.headers['Access-Control-Allow-Origin'] =
request.headers.get('Origin') || '*'
from || '*'

return
}
Expand Down Expand Up @@ -253,7 +253,7 @@ export const cors = (
handleOrigin(set as any, request)
handleMethod(set, request.method)

if (exposedHeaders.length)
if (allowedHeaders.length)
set.headers['Access-Control-Allow-Headers'] =
typeof allowedHeaders === 'string'
? allowedHeaders
Expand All @@ -262,14 +262,14 @@ export const cors = (
if (maxAge)
set.headers['Access-Control-Max-Age'] = maxAge.toString()

return new Response('', {
return new Response(null, {
status: 204
})
}).options('/*', ({ set, request }) => {
handleOrigin(set as any, request)
handleMethod(set, request.method)

if (exposedHeaders.length)
if (allowedHeaders.length)
set.headers['Access-Control-Allow-Headers'] =
typeof allowedHeaders === 'string'
? allowedHeaders
Expand All @@ -278,7 +278,7 @@ export const cors = (
if (maxAge)
set.headers['Access-Control-Max-Age'] = maxAge.toString()

return new Response('', {
return new Response(null, {
status: 204
})
})
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
"types": ["bun-types"], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "resolveJsonModule": true, /* Enable importing .json files. */
Expand Down Expand Up @@ -97,7 +96,7 @@
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
},
// "include": ["src/**/*"]
Expand Down

0 comments on commit c069ff9

Please sign in to comment.