Skip to content

Commit 6a4593b

Browse files
committed
:wrenchls
1 parent 345b4a5 commit 6a4593b

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2+
# 0.8.0-rc.0 - 15 Dec 2023
3+
Change:
4+
- Add support for Elysia 0.8
5+
16
# 0.7.2 - 14 Nov 2023
27
Bug fix:
38
- Response using origin instead of '*' when presented

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elysiajs/cors",
3-
"version": "0.8.0-rc.0",
3+
"version": "0.8.0-rc.1",
44
"description": "Plugin for Elysia that for Cross Origin Requests (CORs)",
55
"author": {
66
"name": "saltyAom",

src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-case-declarations */
12
import { Elysia, type Context } from 'elysia'
23

34
type Origin = string | RegExp | ((request: Request) => boolean | void)
@@ -181,13 +182,15 @@ export const cors = (
181182
const processOrigin = (origin: Origin, request: Request, from: string) => {
182183
switch (typeof origin) {
183184
case 'string':
184-
// eslint-disable-next-line no-case-declarations
185185
const protocolStart = from.indexOf('://')
186+
if (protocolStart !== -1)
187+
from = from.slice(protocolStart + 3)
186188

187-
// Malform URL, invalid protocol
188-
if (protocolStart === -1) return false
189+
const trailingSlash = from.indexOf('/', 0)
190+
if (trailingSlash !== -1)
191+
from = from.slice(trailingSlash)
189192

190-
return origin === from.slice(protocolStart + 3)
193+
return origin === from
191194

192195
case 'function':
193196
return origin(request)

0 commit comments

Comments
 (0)