File tree Expand file tree Collapse file tree 4 files changed +17
-15
lines changed Expand file tree Collapse file tree 4 files changed +17
-15
lines changed Original file line number Diff line number Diff line change
1
+ # 0.7.2 - 14 Nov 2023
2
+ Bug fix:
3
+ - Response using origin instead of '* ' when presented
4
+
1
5
# 0.7.1 - 26 Sep 2023
2
6
Bug fix:
3
7
- strictly handle ` string[] `
Original file line number Diff line number Diff line change @@ -4,21 +4,20 @@ import { cors } from '../src/index'
4
4
const app = new Elysia ( )
5
5
. use (
6
6
cors ( {
7
- origin : [ 'gehenna.sh' , 'saltyaom.com' ]
7
+ credentials : true
8
8
} )
9
9
)
10
10
. get ( '/' , ( ) => 'A' )
11
11
. listen ( 3000 )
12
12
13
13
console . log ( `Elysia is running at ${ app . server ?. hostname } :${ app . server ?. port } ` )
14
14
15
- app . fetch (
16
- new Request ( 'http://localhost/awd' , {
17
- headers : {
18
- origin : 'https://saltyaom.com'
19
- }
20
- } )
21
- )
15
+ // app.fetch(
16
+ // new Request('http://localhost/awd', {
17
+ // headers: {
18
+ // origin: 'https://saltyaom.com'
19
+ // }
20
+ // })
21
+ // )
22
22
23
23
export type App = typeof app
24
- console . log ( 'Server is running on port 3000.' )
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @elysiajs/cors" ,
3
- "version" : " 0.7.1 " ,
3
+ "version" : " 0.7.2 " ,
4
4
"description" : " Plugin for Elysia that for Cross Origin Requests (CORs)" ,
5
5
"author" : {
6
6
"name" : " saltyAom" ,
Original file line number Diff line number Diff line change 1
- import { Elysia , Handler , Context } from 'elysia'
2
-
3
- import { isAbsolute } from 'path'
1
+ import { Elysia , type Context } from 'elysia'
4
2
5
3
type Origin = string | RegExp | ( ( request : Request ) => boolean | void )
6
4
@@ -183,6 +181,7 @@ export const cors = (
183
181
const processOrigin = ( origin : Origin , request : Request , from : string ) => {
184
182
switch ( typeof origin ) {
185
183
case 'string' :
184
+ // eslint-disable-next-line no-case-declarations
186
185
const protocolStart = from . indexOf ( '://' )
187
186
188
187
// Malform URL, invalid protocol
@@ -202,7 +201,7 @@ export const cors = (
202
201
// origin === `true` means any origin
203
202
if ( origin === true ) {
204
203
set . headers [ 'Vary' ] = '*'
205
- set . headers [ 'Access-Control-Allow-Origin' ] = '*'
204
+ set . headers [ 'Access-Control-Allow-Origin' ] = request . headers . get ( 'Origin' ) || '*'
206
205
207
206
return
208
207
}
@@ -218,7 +217,7 @@ export const cors = (
218
217
if ( value === true ) {
219
218
set . headers [ 'Vary' ] = origin ? 'Origin' : '*'
220
219
set . headers [ 'Access-Control-Allow-Origin' ] =
221
- request . headers . get ( 'Origin' ) ?? '*'
220
+ request . headers . get ( 'Origin' ) || '*'
222
221
223
222
return
224
223
}
You can’t perform that action at this time.
0 commit comments